[Python-ideas] Decimal literal?
Adam Olsen
rhamph at gmail.com
Thu Dec 4 22:18:32 CET 2008
On Thu, Dec 4, 2008 at 1:18 PM, Leif Walsh <leif.walsh at gmail.com> wrote:
> Coming in to the thread _way_ late, here's my $0.015:
>
> Sure, it would be great to have an accurate and fast implementation of
> decimal/floating point numbers active by default in the language. We
> don't have that yet. We have a fast implementation, and we have an
> accurate one, and until we have both, there is a decision to be made:
> which one is easy to use (in builtins, has literals, (etc.?)), and
> which one is the "opt-in" implementation (needs a module import, needs
> a constructor)?
>
> We've been dealing with roughly the same fast and sometimes-inaccurate
> floating-point implementation for what, almost 40 years of C
> programming so far. Given that there exist accurate implementations
> of decimal numbers (GMP, MAPM), why hasn't C moved to make one of
> these the "default" implementation?
>
> Whatever the answer, it seems to me that this sets a sort of precedent
> in programming that fast floating-point numbers are favored over
> accurate floating-point numbers. GMP is blindingly fast, and it isn't
> C's default. Decimal is, I think I saw someone mention "hundreds of
> times slower" than the current float implementation.
GMP may be blindingly fast for an arbitrary precision floating point
implementation, but it's quite slow compared to hardware floating
point. Even in hardware there's a temptation to optimize for
single-precision and skip various IEEE 754 special cases that would
slow things down. Performance really does count.
You're not going to find a broad solution here. Decimal is mildly
more precise, but substantially slower. It's also less convenient for
interacting with C code.
Given the importance of C extensions to Python, interacting with C is
the strongest argument here. It's not an elegant reason, but it's
very practical.
Besides, any user WILL have to learn what floats do to their numbers,
so you might as well make it obvious. If you really want to avoid it
you should be using a symbolic math library instead. Personally, if I
need a calculator I usually use Qalculate, rather than an interactive
interpreter.
--
Adam Olsen, aka Rhamphoryncus
More information about the Python-ideas
mailing list