Next floating point number

Steven D'Aprano steve at REMOVETHIScyber.com.au
Sat Dec 17 18:27:16 EST 2005


On Sat, 17 Dec 2005 09:26:39 +0000, Bengt Richter wrote:


> I wonder if this won't work (for IEEE 754 double that is)
> 
> from math import frexp
> def nextf(x, y):
>     f,e = frexp(x)
>     if (f==0.5 or f==-0.5) and x>=y: eps = 2.0**-54
>     else: eps = 2.0**-53
>     if x<y: return (f+eps)*2.0**e
>     else: return (f-eps)*2.0**e

Doesn't that assume floats are 64 bits? Is it possible that they might
not be on some platform or another?



-- 
Steven.




More information about the Python-list mailing list