Re: [Chicken-users] Numbers weirdness

2016-04-22 Thread Andy Bennett
Hi, >> I'm mostly using log2 to work out if numbers are a power of two and find >> the highest bit that they have set. >> >> Is there a more robust way to do that in CHICKEN when using the numbers >> egg and bignums? > > It's probably better to do something like this: > > (= (arithmetic-shift 1

Re: [Chicken-users] Numbers weirdness

2016-04-01 Thread John Cowan
Andy Bennett scripsit: > I'm mostly using log2 to work out if numbers are a power of two and find > the highest bit that they have set. You can use integer-length to tell how many bits are required. If you subtract 1 and the number of bits shrinks by 1, you have a power of 2. Rules for WWI

Re: [Chicken-users] Numbers weirdness

2016-04-01 Thread Peter Bex
On Fri, Apr 01, 2016 at 06:23:28PM +0100, Andy Bennett wrote: > Thanks Peter! > > I'm mostly using log2 to work out if numbers are a power of two and find > the highest bit that they have set. > > Is there a more robust way to do that in CHICKEN when using the numbers > egg and bignums? It's

Re: [Chicken-users] Numbers weirdness

2016-04-01 Thread John Cowan
Peter Bex scripsit: > That's a complete mischaracterisation. First, it depends on your > definition of "accurately", and secondly, you can tell CHICKEN to > change the print precision. See my other mail, which shows that > Racket is _also_ truncating the value, just after more digits than >

Re: [Chicken-users] Numbers weirdness

2016-04-01 Thread Andy Bennett
Hi, >> Is it just late on a Friday? Am I crazy? > > Floating point numbers are weird enough to drive anyone bat shit: > > #;1> (use numbers) > #;2> (define (log2 n) (/ (log n) (log 2))) > #;3> (log2 (expt 2 251)) > 251.0 > #;4> (flonum-print-precision 100) > 15 > #;5> (log2 (expt 2 251)) >

Re: [Chicken-users] Numbers weirdness

2016-04-01 Thread Peter Bex
On Fri, Apr 01, 2016 at 12:48:54PM -0400, John Cowan wrote: > Trying (log2 (expt 2 251)) in Racket, which prints 64-bit floats > accurately (unlike Chicken, which depends on C to do it) That's a complete mischaracterisation. First, it depends on your definition of "accurately", and secondly, you

Re: [Chicken-users] Numbers weirdness

2016-04-01 Thread Peter Bex
On Fri, Apr 01, 2016 at 05:25:44PM +0100, Andy Bennett wrote: > Hi, > > In CHICKEN 4.9.0rc1 and 4.10.0 both with numbers 4.6: > > - > #;1> (use numbers) > #;2> (define (log2 n) (/ (log n) (log 2))) > #;3> (= (log2 (expt 2 252)) (ceiling (log2 (expt 2 252 > #t > #;4> (= (log2 (expt 2

Re: [Chicken-users] Numbers weirdness

2016-04-01 Thread John Cowan
Andy Bennett scripsit: > #;5> (log2 (expt 2 251)) > 251.0 > #;6> (ceiling (log2 (expt 2 251))) > 252.0 > > Is it just late on a Friday? Am I crazy? Trying (log2 (expt 2 251)) in Racket, which prints 64-bit floats accurately (unlike Chicken, which depends on C to do it) returns a value of

[Chicken-users] Numbers weirdness

2016-04-01 Thread Andy Bennett
Hi, In CHICKEN 4.9.0rc1 and 4.10.0 both with numbers 4.6: - #;1> (use numbers) #;2> (define (log2 n) (/ (log n) (log 2))) #;3> (= (log2 (expt 2 252)) (ceiling (log2 (expt 2 252 #t #;4> (= (log2 (expt 2 251)) (ceiling (log2 (expt 2 251 #f #;5> (log2 (expt 2 251)) 251.0 #;6> (ceiling