-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfloatlit_test.go
More file actions
63 lines (58 loc) · 1.19 KB
/
floatlit_test.go
File metadata and controls
63 lines (58 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//go:build !llgo
// +build !llgo
package plan9asm
import (
"math"
"strings"
"testing"
)
func TestFormatLLVMFloat64LiteralFinite(t *testing.T) {
cases := []float64{
0,
-0,
1,
-2,
0.5,
-0.25,
1024,
-1024,
}
for _, v := range cases {
s := formatLLVMFloat64Literal(v)
i := strings.IndexByte(s, 'e')
if i >= 0 {
if !strings.Contains(s[:i], ".") {
t.Fatalf("literal %q for %v has no decimal point before exponent", s, v)
}
continue
}
if !strings.Contains(s, ".") {
t.Fatalf("literal %q for %v has no decimal point", s, v)
}
}
}
func TestFormatLLVMFloat64LiteralSpecial(t *testing.T) {
cases := []float64{math.Inf(1), math.Inf(-1), math.NaN()}
for _, v := range cases {
s := formatLLVMFloat64Literal(v)
if !strings.HasPrefix(s, "0x") {
t.Fatalf("special literal %q is not hex", s)
}
}
}
func TestFormatLLVMFloat64LiteralExactForms(t *testing.T) {
cases := []struct {
in float64
want string
}{
{1, "1.0e+00"},
{2.5, "2.5e+00"},
{-3, "-3.0e+00"},
{0, "0.0e+00"},
}
for _, tc := range cases {
if got := formatLLVMFloat64Literal(tc.in); got != tc.want {
t.Fatalf("formatLLVMFloat64Literal(%v) = %q, want %q", tc.in, got, tc.want)
}
}
}