4
4
package exmath
5
5
6
6
import (
7
+ "fmt"
7
8
"math"
8
9
"testing"
9
10
)
@@ -27,11 +28,11 @@ func TestRound(t *testing.T) {
27
28
28
29
{0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
29
30
{1.390671161567e-309 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, // denormal
30
- {0.49999999999999994 , 0 , 1 , 0.5 , 0.5 , 0.5 , 0.5 , 0.5 , 0.5 , 0.5 }, // 0.5-epsilon
31
+ {0.49999999999999994 , 0 , 0 , 0.5 , 0.5 , 0.5 , 0.5 , 0.5 , 0.5 , 0.5 }, // 0.5-epsilon
31
32
{0.5 , 0 , 1 , 0.5 , 0.5 , 0.5 , 0.5 , 0.5 , 0.5 , 0.5 },
32
33
{0.5000000000000001 , 0 , 1 , 0.5 , 0.5 , 0.5 , 0.5 , 0.5 , 0.5 , 0.5 }, // 0.5+epsilon
33
- {- 1.5 , 0 , - 1 , - 1.5 , - 1.5 , - 1.5 , - 1.5 , - 1.5 , - 1.5 , - 1.5 },
34
- {- 2.5 , 0 , - 2 , - 2.5 , - 2.5 , - 2.5 , - 2.5 , - 2.5 , - 2.5 , - 2.5 },
34
+ {- 1.5 , 0 , - 2 , - 1.5 , - 1.5 , - 1.5 , - 1.5 , - 1.5 , - 1.5 , - 1.5 },
35
+ {- 2.5 , 0 , - 3 , - 2.5 , - 2.5 , - 2.5 , - 2.5 , - 2.5 , - 2.5 , - 2.5 },
35
36
{math .NaN (), math .NaN (), math .NaN (), math .NaN (), math .NaN (), math .NaN (), math .NaN (), math .NaN (), math .NaN (), math .NaN ()},
36
37
{math .Inf (1 ), math .Inf (1 ), math .Inf (1 ), math .Inf (1 ), math .Inf (1 ), math .Inf (1 ), math .Inf (1 ), math .Inf (1 ), math .Inf (1 ), math .Inf (1 )},
37
38
}
@@ -44,14 +45,16 @@ func TestRound(t *testing.T) {
44
45
{2251799813685249.5 , 2251799813685249.5 , 2251799813685250 , 2251799813685250 , 2251799813685200 , 2251799813685000 , 2251799813690000 , 2251799813700000 , 2251799814000000 , 2251799810000000 },
45
46
{2251799813685250.5 , 2251799813685250.5 , 2251799813685251 , 2251799813685250 , 2251799813685300 , 2251799813685000 , 2251799813690000 , 2251799813700000 , 2251799814000000 , 2251799810000000 },
46
47
{4503599627370495.5 , 4503599627370495 , 4503599627370496 , 4503599627370500 , 4503599627370500 , 4503599627370000 , 4503599627370000 , 4503599627400000 , 4503599627000000 , 4503599630000000 },
47
- {4503599627370497 , 4503599627370497 , 4503599627370498 , 4503599627370500 , 4503599627370500 , 4503599627370000 , 4503599627370000 , 4503599627400000 , 4503599627000000 , 4503599630000000 },
48
+ {4503599627370497 , 4503599627370497 , 4503599627370497 , 4503599627370500 , 4503599627370500 , 4503599627370000 , 4503599627370000 , 4503599627400000 , 4503599627000000 , 4503599630000000 },
49
+ {169543.34596 , 169543.3 , 169543 , 169540 , 169500 , 170000 , 170000 , 200000 , 0 , 0 },
48
50
}
49
51
50
52
for _ , cases := range vf {
51
53
expected := []float64 {cases .pm1 , cases .p0 , cases .p1 , cases .p2 , cases .p3 , cases .p4 , cases .p5 , cases .p6 , cases .p7 }
52
54
for precision := - 1 ; precision < 8 ; precision ++ {
53
55
if actual := Round (cases .v , precision ); actual != expected [precision + 1 ] && ! (math .IsNaN (actual ) && math .IsNaN (expected [precision + 1 ])) {
54
- t .Errorf ("Round(%f, %d) %f != %f" , cases .v , precision , actual , expected [precision + 1 ])
56
+ fmt .Println (cases .v , precision , actual , Round (0.5 , precision ))
57
+ t .Errorf ("Round(%v, %d) %f != %f" , cases .v , precision , actual , expected [precision + 1 ])
55
58
}
56
59
}
57
60
}
0 commit comments