Skip to content

Commit

Permalink
Fixed a bug in Atan. Did not correctly handle when input is a large n…
Browse files Browse the repository at this point in the history
…egative value. (#135)

* corrected the last digit of a test expected value (sourced by wolframaplpha.com for correctness)

* fix a bug when the values are large negative values and added tests
  • Loading branch information
nathanhack authored and ericlagergren committed Jul 29, 2019
1 parent 5ff9df8 commit f05d339
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
2 changes: 1 addition & 1 deletion math/arccosine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestAcos(t *testing.T) {
x, r string
}{
0: {"-1.00", "3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068"},
1: {"-.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", "3.141592653589793238462643383279502884197169399375091678839320861357328389398966901647249128623363298"},
1: {"-.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", "3.141592653589793238462643383279502884197169399375091678839320861357328389398966901647249128623363299"},
2: {"-0.50", "2.094395102393195492308428922186335256131446266250070547316629728205210937524139332418689883561411379"},
3: {"0", "1.570796326794896619231321691639751442098584699687552910487472296153908203143104499314017412671058534"},
4: {"0.5", "1.047197551196597746154214461093167628065723133125035273658314864102605468762069666209344941780705689"},
Expand Down
6 changes: 6 additions & 0 deletions math/arctangent.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ func Atan(z, x *decimal.Big) *decimal.Big {
return z
}

//when x <-1 we use -atan(-x) instead
if x.Cmp(negone) < 0 {
Atan(z, new(decimal.Big).Neg(x))
return z.Neg(z)
}

y, ySq, ySqPlus1, segment, halfed := prepAtan(z, x, ctx) // z == y, maybe.
result := BinarySplitDynamic(ctx,
func(_ uint64) *decimal.Big { return y },
Expand Down
Loading

0 comments on commit f05d339

Please sign in to comment.