Finding size of Variable
rosuav at gmail.com
Wed Feb 12 10:24:09 CET 2014
On Wed, Feb 12, 2014 at 7:57 PM, Jussi Piitulainen
<jpiitula at ling.helsinki.fi> wrote:
>> In Python, integers have arbitrary precision, but floats, Fractions,
>> and Decimals, don't. Nearly any operation on arbitrarily large
>> numbers will be either more accurate or more efficient (maybe both)
>> with integers than with any of the other types.
> Is that true about Fractions?
I'm not 100% sure if fraction.Fraction and decimal.Decimal ever limit
the size or precision of their data, but certainly if they don't,
it'll be at horrendous expense of performance. (Decimal can add and
subtract in reasonable time complexity, but multiplication and
division will get slow when you have huge numbers of digits. Fraction
can multiply and divide efficiently, but will get crazily slow on
addition and subtraction.) Integers are an optimized case in many
ways. I can do accurate arbitrary-precision integer arithmetic without
worrying about simple operations suddenly saturating the CPU. I can't
do that with non-integers in any way.
It's not optimized for natural numbers (nonnegative integers), as
negatives are just as cheap as positives, but it's certainly an
optimization for integers.
More information about the Python-list