[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] most-{positive,negative}-fixnum
From: |
Alejandro Forero Cuervo |
Subject: |
Re: [Chicken-users] most-{positive,negative}-fixnum |
Date: |
Mon, 22 May 2006 18:52:52 -0500 |
User-agent: |
Mutt/1.5.9i |
> I need to determine the most positive and most negative fixnums,
> given that Chicken has both 32-bit and 64-bit builds. Can these
> be added as constants, or is there some easy way to compute them?
I used the following:
(use format)
(define (find type)
(let loop ((i type) (mult 2))
(format (current-error-port) "Try: ~A (~A)~%" i mult)
(cond
((fixnum? (round (+ type (* i mult)))) (loop (round (+ type (* i
mult))) mult))
((> mult 1.0000000000001) (loop i (/ (+ mult 1) 2)))
((fixnum? (+ type i)) (loop (+ type i) mult))
(else i))))
(format (current-error-port) "Range: ~A to ~A~%" (find -1) (find 1))
In my build this gives:
Range: -1073741824 to 1073741823
Note, however, that you can use doubles to represent greater numbers
without losing precision (since, AFAIR, doubles can use more bits for
their non-decimal part than integers/fixnums can).
Alejo.
http://azul.freaks-unidos.net/