Hacker News new | ask | show | jobs
by zokier 1929 days ago
0 is actually what I'd expect as an answer. Even on very modern Python you get

    In [1]: 2.0**64 - (2.0**64-1.0)
    Out[1]: 0.0
Thats how floats behave like with operands that differ greatly in magnitude. Also this

    In [2]: 2.0**64 == (2.0**64 - 1.0)
    Out[2]: True
2 comments

> 0 is actually what I'd expect as an answer. Even on very modern Python you get

Given a four byte mantissa, it should be 1 for anything under and equal to 2^32 and 0 for anything over 2^32. Instead it outputted some random number. A bug in checking the flags or some-such. Or maybe a bug in the float to string routine.

The sign takes one bit off the mantissa.
"1" in Scheme:

    >(- (expt 2 64) (- (expt 2 64) 1))
    1
http://people.csail.mit.edu/jaffer/SCM.html
Are you sure that isn't just doing integer math? I don't have a scheme implementation handy, but I tried it in sbcl Common Lisp and while (- (expt 2 64) (- (expt 2 64) 1)) does yield 1,

(- (expt 2.0 64) (- (expt 2.0 64) 1)) yields 0.

True, 0. But I think Guile had an exact->inexact function.