Skip to content

Commit

Permalink
Fix 'math' tests to tolerate float imprecision (google#409)
Browse files Browse the repository at this point in the history
The `math.tan(math.pi / 4) == 1` test and its negative pi counter part
fails under arm64 architecture.

Use `assert.true(near(...))` to tolerate float imprecision, like the
other 8 instances in the same test data file.

Tested on 24 combinations of OS x arch x Go version.
- {linux, darwin} x {arm64, amd64} x  go1.{16, 17, 18}
  • Loading branch information
bdd authored Aug 15, 2022
1 parent 064bc72 commit e9e71af
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions starlark/testdata/math.star
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ assert.fails(lambda: math.sin("0"), "got string, want float or int")
# tan
assert.eq(math.tan(0.0), 0)
assert.eq(math.tan(0), 0)
assert.eq(math.tan(math.pi / 4), 1)
assert.eq(math.tan(-math.pi / 4), -1)
assert.true(near(math.tan(math.pi / 4), 1, 0.00000000000001))
assert.true(near(math.tan(-math.pi / 4), -1, 0.00000000000001))
assert.eq(math.tan(inf), nan)
assert.eq(math.tan(-inf), nan)
assert.eq(math.tan(nan), nan)
Expand Down

0 comments on commit e9e71af

Please sign in to comment.