| 1 |
// run |
| 2 |
|
| 3 |
// Copyright 2015 The Go Authors. All rights reserved. |
| 4 |
// Use of this source code is governed by a BSD-style |
| 5 |
// license that can be found in the LICENSE file. |
| 6 |
|
| 7 |
// Issue 12577: Test that there are no -0 floating-point constants. |
| 8 |
|
| 9 |
package main |
| 10 |
|
| 11 |
import "math" |
| 12 |
|
| 13 |
const ( |
| 14 |
z0 = 0.0 |
| 15 |
z1 = -0.0 |
| 16 |
z2 = -z0 |
| 17 |
z3 = -z2 |
| 18 |
) |
| 19 |
|
| 20 |
var ( |
| 21 |
x0 float32 = z0 |
| 22 |
x1 float32 = z1 |
| 23 |
x2 float32 = z2 |
| 24 |
x3 float32 = z3 |
| 25 |
|
| 26 |
y0 float64 = z0 |
| 27 |
y1 float64 = z1 |
| 28 |
y2 float64 = z2 |
| 29 |
y3 float64 = z3 |
| 30 |
) |
| 31 |
|
| 32 |
func test32(f float32) { |
| 33 |
if f != 0 || math.Signbit(float64(f)) { |
| 34 |
println("BUG: got", f, "want 0.0") |
| 35 |
return |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
func test64(f float64) { |
| 40 |
if f != 0 || math.Signbit(f) { |
| 41 |
println("BUG: got", f, "want 0.0") |
| 42 |
return |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
func main() { |
| 47 |
if f := -x0; f != 0 || !math.Signbit(float64(f)) { |
| 48 |
println("BUG: got", f, "want -0.0") |
| 49 |
} |
| 50 |
|
| 51 |
test32(-0.0) |
| 52 |
test32(x0) |
| 53 |
test32(x1) |
| 54 |
test32(x2) |
| 55 |
test32(x3) |
| 56 |
|
| 57 |
if f := -y0; f != 0 || !math.Signbit(f) { |
| 58 |
println("BUG: got", f, "want -0.0") |
| 59 |
} |
| 60 |
|
| 61 |
test64(-0.0) |
| 62 |
test64(y0) |
| 63 |
test64(y1) |
| 64 |
test64(y2) |
| 65 |
test64(y3) |
| 66 |
} |