-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_float64_test.go
125 lines (104 loc) · 2.58 KB
/
test_float64_test.go
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package cast
import (
"errors"
"math"
)
type testFloat64er struct {
value string
}
func testFloat64erNegativeInfinity() testFloat64er {
return testFloat64er{value: "negative infinity"}
}
func testFloat64erMin() testFloat64er {
return testFloat64er{value: "min"}
}
func testFloat64erNegativePi() testFloat64er {
return testFloat64er{value: "negative pi"}
}
func testFloat64erNegativeE() testFloat64er {
return testFloat64er{value: "negative e"}
}
func testFloat64erNegativeSqrt2() testFloat64er {
return testFloat64er{value: "negative sqrt(2)"}
}
func testFloat64erNegativeOne() testFloat64er {
return testFloat64er{value: "negative one"}
}
func testFloat64erNegativeLn2() testFloat64er {
return testFloat64er{value: "negative ln(2)"}
}
func testFloat64erNegativeSmallestNonzero() testFloat64er {
return testFloat64er{value: "negative smallest-nonzero"}
}
func testFloat64erZero() testFloat64er {
return testFloat64er{value: "zero"}
}
func testFloat64erSmallestNonzero() testFloat64er {
return testFloat64er{value: "smallest-nonzero"}
}
func testFloat64erLn2() testFloat64er {
return testFloat64er{value: "ln(2)"}
}
func testFloat64erOne() testFloat64er {
return testFloat64er{value: "one"}
}
func testFloat64erSqrt2() testFloat64er {
return testFloat64er{value: "sqrt(2)"}
}
func testFloat64erE() testFloat64er {
return testFloat64er{value: "e"}
}
func testFloat64erPi() testFloat64er {
return testFloat64er{value: "pi"}
}
func testFloat64erMax() testFloat64er {
return testFloat64er{value: "max"}
}
func testFloat64erInfinity() testFloat64er {
return testFloat64er{value: "infinity"}
}
func testFloat64erNaN() testFloat64er {
return testFloat64er{value: "nan"}
}
func (receiver testFloat64er) Float64() (float64, error) {
switch receiver.value {
case "negative infinity":
return math.Inf(-1), nil
case "min":
return -math.MaxFloat64, nil
case "negative pi":
return -math.Pi, nil
case "negative e":
return -math.E, nil
case "negative sqrt(2)":
return -math.Sqrt2, nil
case "negative one":
return -1, nil
case "negative ln(2)":
return -math.Ln2, nil
case "negative smallest-nonzero":
return -math.SmallestNonzeroFloat64, nil
case "zero":
return 0, nil
case "smallest-nonzero":
return math.SmallestNonzeroFloat64, nil
case "ln(2)":
return math.Ln2, nil
case "one":
return 1, nil
case "sqrt(2)":
return math.Sqrt2, nil
case "e":
return math.E, nil
case "pi":
return math.Pi, nil
case "max":
return math.MaxFloat64, nil
case "infinity":
return math.Inf(+1), nil
case "nan":
return math.NaN(), nil
default:
return 0, errors.New("Internal Error")
}
}