Source file
test/fixedbugs/issue14651.go
1
2
3
4
5
6
7
8
9
10
11
12
13 package main
14
15 import (
16 "fmt"
17 "math"
18 )
19
20 const (
21 p149 = 1.0 / (1 << 149)
22 p500 = 1.0 / (1 << 500)
23 p1074 = p500 * p500 / (1<<74)
24 )
25
26 const (
27 m0000p149 = 0x0 / 16.0 * p149
28 m1000p149 = 0x8 / 16.0 * p149
29 m1001p149 = 0x9 / 16.0 * p149
30 m1011p149 = 0xb / 16.0 * p149
31 m1100p149 = 0xc / 16.0 * p149
32
33 m0000p1074 = 0x0 / 16.0 * p1074
34 m1000p1074 = 0x8 / 16.0 * p1074
35 m1001p1074 = 0x9 / 16.0 * p1074
36 m1011p1074 = 0xb / 16.0 * p1074
37 m1100p1074 = 0xc / 16.0 * p1074
38 )
39
40 func main() {
41 test32(float32(m0000p149), f32(m0000p149))
42 test32(float32(m1000p149), f32(m1000p149))
43 test32(float32(m1001p149), f32(m1001p149))
44 test32(float32(m1011p149), f32(m1011p149))
45 test32(float32(m1100p149), f32(m1100p149))
46
47 test64(float64(m0000p1074), f64(m0000p1074))
48 test64(float64(m1000p1074), f64(m1000p1074))
49 test64(float64(m1001p1074), f64(m1001p1074))
50 test64(float64(m1011p1074), f64(m1011p1074))
51 test64(float64(m1100p1074), f64(m1100p1074))
52 }
53
54 func f32(x float64) float32 { return float32(x) }
55 func f64(x float64) float64 { return float64(x) }
56
57 func test32(a, b float32) {
58 abits := math.Float32bits(a)
59 bbits := math.Float32bits(b)
60 if abits != bbits {
61 panic(fmt.Sprintf("%08x != %08x\n", abits, bbits))
62 }
63 }
64
65 func test64(a, b float64) {
66 abits := math.Float64bits(a)
67 bbits := math.Float64bits(b)
68 if abits != bbits {
69 panic(fmt.Sprintf("%016x != %016x\n", abits, bbits))
70 }
71 }
72
View as plain text