Perl is worse!
Tim Peters
tim_one at email.msn.com
Fri Jul 28 21:48:29 EDT 2000
[Grant Edwards]
> ...
> I guess I never looked into the details in Python (haven't done much
> numerical stuff yet). I had sort of assumed that floating point
> values were 32 bit, but if they're 64, then as you say, the problem is
> postponed until long ints are involved.
A Python float is a C double, which on all Python platforms I know of is a
64-bit format, and on almost all conforms to IEEE-754 so has 53 bits of
precision (so all integers i with abs(i) <= 2.**53 are exactly
representable, and note that "<=" instead of "<" is not a typo despite your
first impression <wink>).
A Python int is a C long, and that varies more widely. On most platforms
that's 4 bytes, so conversion to (Python) float cannot lose info. On some
platforms it's 8 bytes, though, and conversion to (Python) float *can* lose
info on those.
There wasn't a lot of thought given to numeric endcases in Python at first,
simply because its initial audience did not have many number-crunchers, and
building robust portable semantics on top of C is a PITA since K&R C itself
was sloppy about its numerics.
it's-pretty-accurate-to-call-python's-numeric-policies-"benign-neglect"-ly
y'rs - tim
More information about the Python-list
mailing list