44package exmath
55
66import (
7+ "fmt"
78 "math"
89 "testing"
910)
@@ -27,11 +28,11 @@ func TestRound(t *testing.T) {
2728
2829 {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
2930 {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
3132 {0.5 , 0 , 1 , 0.5 , 0.5 , 0.5 , 0.5 , 0.5 , 0.5 , 0.5 },
3233 {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 },
3536 {math .NaN (), math .NaN (), math .NaN (), math .NaN (), math .NaN (), math .NaN (), math .NaN (), math .NaN (), math .NaN (), math .NaN ()},
3637 {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 )},
3738 }
@@ -44,14 +45,16 @@ func TestRound(t *testing.T) {
4445 {2251799813685249.5 , 2251799813685249.5 , 2251799813685250 , 2251799813685250 , 2251799813685200 , 2251799813685000 , 2251799813690000 , 2251799813700000 , 2251799814000000 , 2251799810000000 },
4546 {2251799813685250.5 , 2251799813685250.5 , 2251799813685251 , 2251799813685250 , 2251799813685300 , 2251799813685000 , 2251799813690000 , 2251799813700000 , 2251799814000000 , 2251799810000000 },
4647 {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 },
4850 }
4951
5052 for _ , cases := range vf {
5153 expected := []float64 {cases .pm1 , cases .p0 , cases .p1 , cases .p2 , cases .p3 , cases .p4 , cases .p5 , cases .p6 , cases .p7 }
5254 for precision := - 1 ; precision < 8 ; precision ++ {
5355 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 ])
5558 }
5659 }
5760 }
0 commit comments