Gerhard Niklasch on Mon, 2 Apr 2001 08:00:15 +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.0104020109490.6239-100000@pev.math.univ-montp2.fr> > Date: Mon, 2 Apr 2001 01:27:17 +0200 (CEST) > From: Philippe Elbaz-Vincent <pev@pev.math.univ-montp2.fr> > To: pari-dev list <pari-dev@list.cr.yp.to> > > Is the following an expected behavior ? Yes. > (01:23) gp > 1390.48+171364.53 > time = 0 ms. > %1 = 172755.0099999999999999999999 > (01:24) gp > Where's the problem here? Use \x to check out the actual bit patterns of the summands. Note that neither .48 nor .53 can be exactly represented as a finite dyadic fraction (and thus as a PARI t_REAL of finite precision). The actual operands are rounded approximations to the decimal fractions, and it just so happens that their sum, rounded again (to get rid of the three extra bits con- tributed at the least significant end by the smaller summand), converts back to a decimal fraction which is one unit below the infinite-precision result in the least significant digit position. The result is correct to within the precision used to represent the operands. (NB the integer parts don't matter so long as their sizes conspire to get the right bits of the periodic dyadic ex- pansions lined up, and get them cut off and rounded at the same positions within their periods. 1200.48+170000.53 will show the same behaviour.) This is not PARI-specific in any way, this is material for the first week in any numerical analysis course. :) Cheers, Gerhard