Skip to content

Commit

Permalink
handle +/-inf.0 and +nan.0 in atan #299
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Feb 11, 2024
1 parent 4d5c14d commit 5889985
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion dist/std.min.scm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions dist/std.scm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/std.xcb
Binary file not shown.
16 changes: 12 additions & 4 deletions lib/R5RS.scm
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,18 @@
If two argumets are passed and they are not complex numbers

Check failure on line 542 in lib/R5RS.scm

View workflow job for this annotation

GitHub Actions / Check for spelling errors

argumets ==> arguments
it calulates Math.atan2 on those arguments."

Check failure on line 543 in lib/R5RS.scm

View workflow job for this annotation

GitHub Actions / Check for spelling errors

calulates ==> calculates
(if (and (null? rest) (complex? z))
(let ((iz (* +i z)))
(* (/ 1 +2i)
(log (/ (+ 1 iz)
(- 1 iz)))))
(cond ((nan? z) +nan.0)
((infinite? z)
(let ((atan (/ Math.PI 2)))
(if (< z 0)
(- atan)
atan)))
(else
;; ref: https://youtu.be/d93AarE0lKg
(let ((iz (* +i z)))
(* (/ 1 +2i)
(log (/ (+ 1 iz)
(- 1 iz)))))))
(let ((x z) (y (car rest)))
(if (and (zero? (imag-part x))
(zero? (imag-part y)))
Expand Down
6 changes: 5 additions & 1 deletion tests/numbers.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,11 @@
(t.is (atan 0.5 0.6) 0.6947382761967033)
(t.is (atan -0.5 0.6) -0.6947382761967033)
(t.is (atan 0.5 -0.6) 2.44685437739309)
(t.is (atan -0.5 -0.6) -2.44685437739309)))
(t.is (atan -0.5 -0.6) -2.44685437739309)

(t.is (atan +inf.0) 1.5707963267948966)
(t.is (atan -inf.0) -1.5707963267948966)
(t.is (atan +nan.0) +nan.0)))

(test "numbers: should calculate odd? / even?"
(lambda (t)
Expand Down

0 comments on commit 5889985

Please sign in to comment.