diff options
author | Mark H Weaver <mhw@netris.org> | 2013-07-16 17:38:14 -0400 |
---|---|---|
committer | Mark H Weaver <mhw@netris.org> | 2013-07-16 17:38:14 -0400 |
commit | 06903786211afd9a554b8f009a37111f729607ee (patch) | |
tree | 01d1760bf2bfb2a11f27450a8ae33d59e7129446 /module/rnrs | |
parent | 1f4f2a12d093fe4f156ef25ebc4a25d05185e5f9 (diff) | |
download | guile-06903786211afd9a554b8f009a37111f729607ee.tar.gz |
Fix R6RS 'fixnum-width'.
Fixes <http://bugs.gnu.org/14879>.
Reported by Göran Weinholt <goran@weinholt.se>.
* module/rnrs/arithmetic/fixnums.scm (fixnum-width): Rewrite to avoid
inexact arithmetic, and correct the off-by-one error.
* test-suite/tests/r6rs-arithmetic-fixnums.test (fixnum-width): Add
tests.
Diffstat (limited to 'module/rnrs')
-rw-r--r-- | module/rnrs/arithmetic/fixnums.scm | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/module/rnrs/arithmetic/fixnums.scm b/module/rnrs/arithmetic/fixnums.scm index dbf9ee746..7a5a6215e 100644 --- a/module/rnrs/arithmetic/fixnums.scm +++ b/module/rnrs/arithmetic/fixnums.scm @@ -95,8 +95,11 @@ (rnrs exceptions (6)) (rnrs lists (6))) - (define fixnum-width - (let ((w (inexact->exact (round (/ (log (+ most-positive-fixnum 1)) (log 2)))))) + (define fixnum-width + (let ((w (do ((i 0 (+ 1 i)) + (n 1 (* 2 n))) + ((> n most-positive-fixnum) + (+ 1 i))))) (lambda () w))) (define (greatest-fixnum) most-positive-fixnum) |