blob: d7ebb1288eb820cce4d777e6d57af66b51301f52 [file] [log] [blame]
Robert Griesemer646939c2016-03-03 18:26:36 -08001// 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
10package main
11
12import (
13 "fmt"
14 "math"
15)
16
17func main() {
18 for _, t := range []struct {
19 value float32
20 bits uint32
21 }{
22 {0e+00, 0x00000000},
Robert Griesemerc12e1b02016-03-18 13:38:52 -070023 {1e-46, 0x00000000},
24 {0.5e-45, 0x00000000},
25 {0.8e-45, 0x00000001},
26 {1e-45, 0x00000001},
Robert Griesemer646939c2016-03-03 18:26:36 -080027 {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}