aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorerifan01 <eric.fang@arm.com>2017-11-28 03:38:03 +0000
committerRobert Griesemer <gri@golang.org>2018-04-17 03:17:22 +0000
commit6d5ebc70225aeb71a60061e5cf755c5852ac13da (patch)
tree4a91625e79af77a9df750988a248bb1a32c27557 /src
parenta2ffe3e625b05217e8d44dcda43138fc61390666 (diff)
downloadgo-6d5ebc70225aeb71a60061e5cf755c5852ac13da.tar.xz
math: add a testcase for Mod and Remainder respectively
One might try to implement the Mod or Remainder function with the expression x - TRUNC(x/y + 0.5)*y, but in fact this method is wrong, because the rounding of (x/y + 0.5) to initialize the argument of TRUNC may lose too much precision. However, the current test cases can not detect this error. This CL adds two test cases to prevent people from continuing to do such attempts. Change-Id: I6690f5cffb21bf8ae06a314b7a45cafff8bcee13 Reviewed-on: https://go-review.googlesource.com/84275 Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/math/all_test.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/math/all_test.go b/src/math/all_test.go
index 1ac8ce886c..87df89e812 100644
--- a/src/math/all_test.go
+++ b/src/math/all_test.go
@@ -2435,6 +2435,10 @@ func TestMod(t *testing.T) {
t.Errorf("Mod(%g, %g) = %g, want %g", vffmodSC[i][0], vffmodSC[i][1], f, fmodSC[i])
}
}
+ // verify precision of result for extreme inputs
+ if f := Mod(5.9790119248836734e+200, 1.1258465975523544); 0.6447968302508578 != f {
+ t.Errorf("Remainder(5.9790119248836734e+200, 1.1258465975523544) = %g, want 0.6447968302508578", f)
+ }
}
func TestFrexp(t *testing.T) {
@@ -2776,6 +2780,10 @@ func TestRemainder(t *testing.T) {
t.Errorf("Remainder(%g, %g) = %g, want %g", vffmodSC[i][0], vffmodSC[i][1], f, fmodSC[i])
}
}
+ // verify precision of result for extreme inputs
+ if f := Remainder(5.9790119248836734e+200, 1.1258465975523544); -0.4810497673014966 != f {
+ t.Errorf("Remainder(5.9790119248836734e+200, 1.1258465975523544) = %g, want -0.4810497673014966", f)
+ }
}
func TestRound(t *testing.T) {