Debian Codegraph @

test/fixedbugs/issue14553.go

raw
1 // run
2
3 // Copyright 2016 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 // This test checks if the compiler's internal constant
8 // arithmetic correctly rounds denormal float32 values.
9
10 package main
11
12 import (
13 "fmt"
14 "math"
15 )
16
17 func main() {
18 for _, t := range []struct {
19 value float32
20 bits uint32
21 }{
22 {0e+00, 0x00000000},
23 {1e-46, 0x00000000},
24 {0.5e-45, 0x00000000},
25 {0.8e-45, 0x00000001},
26 {1e-45, 0x00000001},
27 {2e-45, 0x00000001},
28 {3e-45, 0x00000002},
29 {4e-45, 0x00000003},
30 {5e-45, 0x00000004},
31 {6e-45, 0x00000004},
32 {7e-45, 0x00000005},
33 {8e-45, 0x00000006},
34 {9e-45, 0x00000006},
35 {1.0e-44, 0x00000007},
36 {1.1e-44, 0x00000008},
37 {1.2e-44, 0x00000009},
38 } {
39 got := math.Float32bits(t.value)
40 want := t.bits
41 if got != want {
42 panic(fmt.Sprintf("bits(%g) = 0x%08x; want 0x%08x", t.value, got, want))
43 }
44 }
45 }