Gerhard Niklasch on Mon, 2 Apr 2001 11:55:00 +0200 (MEST)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [GP/PARI-2.1.0] arithmetic weirdness


In response to:
> Message-ID: <Pine.LNX.4.33.0104020839360.6239-100000@pev.math.univ-montp2.fr>
> Date: Mon, 2 Apr 2001 09:15:16 +0200 (CEST)
> From: Philippe Elbaz-Vincent <pev@pev.math.univ-montp2.fr>
> To: PARI developers <pari-dev@list.cr.yp.to>

> > Where's the problem here?
> 
> because what you see is not what you expect.
> 
> Indeed the simple
> 
> (09:30) gp > .1
> time = 0 ms.
> %25 = 0.09999999999999999999999999999
> 
> is already surprising for me, since again I expected exact
> floating point arithmetic as long as I'm reasonably far from
> "computational limitation for a given realprecision"
> (it's in general what you observe with most of the systems,
> and also for example with a calculator. But as a fact Magma has
> also a peculiar behavior)

The arithmetic is as exact as binary representation allows here.
It is the input .1 which is inexact, and which is correctly
taken to refer to "any number representable in the internal
format which is consistent with this input, and we'll take the
best one among those".

Anything else would require either

(1) decimal representation internally  (at a rather horrible
cost in terms of performance),  or

(2.1) intentionally rounding the wrong way sometimes in
connection with
(2.2) clairvoyance  (in order to know when the user might expect
us to do this!).

I don't think either (1) or (2.2) (or (2.1) for that matter)
is going to happen any time soon... :)

When you know in advance you're working with rationals, and
when the extra speed of t_REAL is not needed, use rational
numbers, and you'll get exact results.

Cheers, Gerhard