Why isn't Python king of the hill?
geoff at homegain.com
Sat Jun 2 13:07:19 CEST 2001
A quick addendum to my earlier spam about number systems -- I've been
corrected privately, and wanted to correct myself publicly lest I mislead
someone. I try not to play fast and loose with the facts, but my
explanations sometimes exceed my understanding <wink>.
Fixed-point is scaled in advance. This means that you do not need to track
the scaling factor: since everything is being done to the same scale,
there's just one scaling factor. You scale all your numbers for storage and
calculation, then move the decimal point back when you want to display them.
Rational numbers are tracked as a numerator and denominator, nothing more
complicated than that. The danger with rational numbers is that they require
a lot of storage space, and that the integers involved sometimes get really,
really big. I'm told that you can't reasonably limit the size of the
integers, either, because if you do, your accuracy will suffer even worse
than if you'd stuck to floats. I guess that means that asking for the answer
to exactly the right question could result in a single absolutely enormous
number, and it could take a very long time to arrive at that number.
I was also informed that when a float and a rational are combined, that the
result should be coerced to a float, because the rational is accurate and
the float is an approximation.
I would credit the source of all this fine information, but I think that
doing so without his permission is something of an ethical violation, since
he sent a private reply? Anyway, I wanted to correct myself soon, so I'll
thank him when I'm allowed. :)
More information about the Python-list