mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-11 22:31:12 +02:00
Added optional second arg to R6RS log function
* module/rnrs/base.scm (log): now takes a base argument, using the change of base formula for logs. * test-suite/tests/r6rs-base.test ("log (2nd arg)"): Add test cases.
This commit is contained in:
parent
62ef23cbb8
commit
cf9d4a8214
2 changed files with 25 additions and 0 deletions
|
@ -74,6 +74,7 @@
|
|||
|
||||
syntax-rules identifier-syntax)
|
||||
(import (rename (except (guile) error raise)
|
||||
(log log-internal)
|
||||
(euclidean-quotient div)
|
||||
(euclidean-remainder mod)
|
||||
(euclidean/ div-and-mod)
|
||||
|
@ -85,6 +86,14 @@
|
|||
(inexact->exact exact))
|
||||
(srfi srfi-11))
|
||||
|
||||
(define log
|
||||
(case-lambda
|
||||
((n)
|
||||
(log-internal n))
|
||||
((n base)
|
||||
(/ (log n)
|
||||
(log base)))))
|
||||
|
||||
(define (boolean=? . bools)
|
||||
(define (boolean=?-internal lst last)
|
||||
(or (null? lst)
|
||||
|
|
|
@ -21,6 +21,22 @@
|
|||
:use-module ((rnrs base) :version (6))
|
||||
:use-module (test-suite lib))
|
||||
|
||||
|
||||
;; numbers are considered =? if their difference is less than a set
|
||||
;; tolerance
|
||||
(define (=? alpha beta)
|
||||
(< (abs (- alpha beta)) 1e-10))
|
||||
|
||||
(with-test-prefix "log (2nd arg)"
|
||||
(pass-if "log positive-base" (=? (log 8 2) 3))
|
||||
(pass-if "log negative-base" (=? (real-part (log 256 -4))
|
||||
0.6519359443))
|
||||
(pass-if "log base-one" (= (log 10 1) +inf.0))
|
||||
(pass-if "log base-zero"
|
||||
(catch #t
|
||||
(lambda () (log 10 0) #f)
|
||||
(lambda args #t))))
|
||||
|
||||
(with-test-prefix "boolean=?"
|
||||
(pass-if "boolean=? null" (boolean=?))
|
||||
(pass-if "boolean=? unary" (boolean=? #f))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue