Skip to content

Commit

Permalink
update log to accept two arguments #301
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Feb 8, 2024
1 parent a43f198 commit 5d8f6a3
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* add immutable strings as in R7RS spec [#285](https://github.com/jcubic/lips/issues/285)
* 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)
### 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
1 change: 1 addition & 0 deletions dist/std.min.scm

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

25 changes: 25 additions & 0 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.
25 changes: 25 additions & 0 deletions lib/R7RS.scm
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,31 @@
(define (truncate-quotient x y) (quotient x y))
(define (truncate-remainder x y) (remainder x y))

(define (log z . rest)
"(log z)
(log z1 z2)

Function that calculates natural logarithm (base e) of z. Where the argument
can be any number (including complex negative and rational). If the value is 0
it returns NaN. It two arguments are provided it will calculate logarithm
of z1 with given base z2."
(if (not (null? rest))
(let ((base (car rest)))
(/ (log z) (log base)))
(cond ((real? z)
(cond ((zero? z) NaN)
((> z 0) (Math.log z))
(else
(+ (Math.log (abs z))
(* Math.PI +i)))))
((complex? z)
(let ((arg (Math.atan2 (imag-part z)
(real-part z))))
(+ (Math.log (z.modulus))
(* +i arg))))
((rational? z)
(log (exact->inexact z))))))

;; -----------------------------------------------------------------------------
(define-syntax case-lambda
(syntax-rules ()
Expand Down

0 comments on commit 5d8f6a3

Please sign in to comment.