finding out the precision of floats
John Machin
sjmachin at lexicon.net
Sun Feb 25 06:20:44 EST 2007
On Feb 25, 9:57 pm, "Arnaud Delobelle" <arno... at googlemail.com> wrote:
> Hi all,
>
> I want to know the precision (number of significant digits) of a float
> in a platform-independent manner. I have scoured through the docs but
> I can't find anything about it!
>
> At the moment I use this terrible substitute:
>
> FLOAT_PREC = repr(1.0/3).count('3')
I'm a little puzzled:
You don't seem to want a function that will tell you the actual number
of significant decimal digits in a particular number e.g.
nsig(12300.0) -> 3
nsig(0.00123400) -> 4
etc
You appear to be trying to determine what is the maximum number of
significant decimal digits afforded by the platform's implementation
of Python's float type. Is Python implemented on a platform that
*doesn't* use IEEE 754 64-bit FP as the in-memory format for floats?
Cheers,
John
More information about the Python-list
mailing list