Skip to content

Commit

Permalink
implement proper atan #299 #34
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Feb 11, 2024
1 parent 97b66d2 commit 4d5c14d
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
* add R7RS `char<...>?` and `string<...>?` functions [#298](https://github.com/jcubic/lips/issues/298)
* improve syntax-rule exception message (appending macro code)
* update `log` to accept two arguments [#301](https://github.com/jcubic/lips/issues/301)
* allow to use `data-bootstrap` attribute
* allow to use `data-bootstrap` attribute on script tags
* make `atan` work for complex numbers
### Bugfix
* fix `let-values` to allow binding to list [#281](https://github.com/jcubic/lips/issues/281)
* fix wrong strings in `string-fill!`
Expand Down
3 changes: 2 additions & 1 deletion dist/std.min.scm

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

21 changes: 20 additions & 1 deletion 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.
21 changes: 20 additions & 1 deletion lib/R5RS.scm
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@

;; -----------------------------------------------------------------------------
;; generate Math functions with documentation
(define _maths (list "sin" "cos" "tan" "asin" "acos" "atan"))
(define _maths (list "asin" "acos"))

;; -----------------------------------------------------------------------------
(define _this_env (current-environment))
Expand Down Expand Up @@ -533,6 +533,25 @@
(Math.cosh im2))))))
(Math.tan n)))

;; -----------------------------------------------------------------------------
(define (atan z . rest)
"(atan z)
(atan x y)

Function calculates arcus tangent of a complex number.
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)))))
(let ((x z) (y (car rest)))
(if (and (zero? (imag-part x))
(zero? (imag-part y)))
(Math.atan2 x y)
(error "atan: can't call with two complex numbers")))))

;; -----------------------------------------------------------------------------
(define (exp n)
"(exp n)
Expand Down
17 changes: 17 additions & 0 deletions tests/numbers.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,23 @@
(1/2+1/2i 0.40389645531602575+0.5640831412674985i)
(+1/2i +0.46211715726000974i)))))

(test "numbers: atan"
(lambda (t)
(t.is (atan 10+10i) 1.5207132443509341+0.04991641756298178i)
(t.is (atan -10+10i) -1.5207132443509341+0.04991641756298178i)
(t.is (atan -10-10i) -1.5207132443509341-0.0499164175629817i)
(t.is (atan 10-10i) 1.5207132443509341-0.0499164175629817i)

(t.is (atan 1/2) 0.46364760900080615)
(t.is (atan 0.5) 0.46364760900080615)
(t.is (atan 1/2 3/4) 0.5880026035475675)
(t.is (atan 2 3) 0.5880026035475675)

(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)))

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

0 comments on commit 4d5c14d

Please sign in to comment.