More int and float attributes

Paddy paddy3118 at netscape.net
Sat Aug 5 15:47:03 EDT 2006


bearophileHUGS at lycos.com wrote:
> sys.maxint gives the largest positive integer supported by Python's
> regular integer type. But maybe such attribute, with few others (they
> can be called min and max) can be given to int type itself.
> D is a very nice language, that I hope to see more used. It is copying
> lot of things from Python. D Floating point values have some
> proprieties:
>
> http://www.digitalmars.com/d/property.html
>
> Properties for Floating Point Types:
> .init		initializer (NaN)
> .infinity	infinity value
> .nan		NaN value
> .dig		number of decimal digits of precision
> .epsilon	smallest increment
> .mant_dig	number of bits in mantissa
> .max_10_exp	maximum exponent as power of 10
> .max_exp	maximum exponent as power of 2
> .min_10_exp	minimum exponent as power of 10
> .min_exp	minimum exponent as power of 2
> .max		largest representable value that's not infinity
> .min		smallest representable value that's not 0
> .re		real part
> .im		imaginary part
>
> I think such attributes may be useful to be added to Python float
> type/values too.
>
> Bye,
> bearophile
The thing about float is that people expect it to be 'fast'. Most CPU's
have two or one representationfor floats that is supported by hardware
and lightning fast compared to a pure software implementation.
The decimal module provides for the 'bean counters' out their who can't
afford to round off a penny, but I must say that this is the first
request I have seen for a flexible float where you would not have
hardware support (when hardware float support is available).

Or do you mean the ability to choose between hardware supported float
s? e.g. float and double precision?
Or to be able to just interrogate the float implementation so your prog
can adjust to whatever implementation it is running under?
Something like:
  assert float.mant_dig > 20


- Paddy.




More information about the Python-list mailing list