Skip to content

Commit

Permalink
add function LOG
Browse files Browse the repository at this point in the history
  • Loading branch information
VitoVan authored and davazp committed May 5, 2023
1 parent 0c21063 commit 4d7e110
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/numbers.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@
(%ash-right x y)
(%ash-left x y))))

;;; log
(defun log (number &optional (base nil base-p))
"Return the logarithm of NUMBER in the base BASE, which defaults to e."
(if base-p
(/ (log number) (log base))
(if (numberp number)
(#j:Math:log number)
(error "`~S' is not a number." number))))

;;; lognot
(defun lognot (x) (%lognot x))

Expand Down
8 changes: 8 additions & 0 deletions tests/numbers.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@
(= #x3FFFC
(ash #xFFFF 2))))

;;; test LOG
(test
(equal 0 (log 1)))
(test
(equal 2 (log 100 10)))
(test
(equal 3 (log 8.0 2)))

;;; test LOGNOT
(test
(equal '(-1 -2 0 999)
Expand Down

0 comments on commit 4d7e110

Please sign in to comment.