Karim Belabas on Tue, 23 Sep 2014 16:34:13 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Non-zero number plus zero is zero? |
* Karim Belabas [2014-09-23 14:23]: > * Jeroen Demeyer [2014-09-23 12:48]: > > The following is probably consistent with PARI's floating point > > model, but it was certainly surprising to me: a non-zero number plus > > 0 can be 0: > > > > gp> 1 + 0e1 > > %1 = 0.E1 > > See section 1.4, "The PARI philosophy", in the user's manual. We spend a > few lines studying an analogous example. > > Thus not a bug. > > > An easy proof of 1 == 0 in PARI/GP: > > > > gp> 0e1 == 1 > > %5 = 1 > > The above is expected, but we indeed have an inconsistency here: > > ? 0e1 == 1.0 > %1 = 0 > > The problem is that 'x==y' is "defined" as equal0(x-y), which explains > your example, but contradicts mine. > > The reason is that the comparison is done as per the definition whenever > x and y have different types only, and via a specialized type-specific > routine otherwise. > > Unfortunately, the equalrr() function is not consistent with the > definition and starts by comparing signs: two t_REAL of different signs > are different. cmprr() and cmpir() have analogous problems: when one of > the t_REAL inputs has sign 0 (of comparatively large exponent), they do > not agree with the definition. > > I will fix that. Done in 'master'. Thanks ! K.B. P.S. Now gp > 0e1 < 1 %1 = 0 gp > 0e1 <= 1 %2 = 1 gp > 0e1 > 1 %3 = 0 gp > 0e1 >= 1 %4 = 1 gp > 0e1 == 1 %5 = 1 gp > 0e1 === 1 %6 = 0 (same with 1 replaced by 1.0). -- Karim Belabas, IMB (UMR 5251) Tel: (+33) (0)5 40 00 26 17 Universite de Bordeaux Fax: (+33) (0)5 40 00 69 50 351, cours de la Liberation http://www.math.u-bordeaux1.fr/~kbelabas/ F-33405 Talence (France) http://pari.math.u-bordeaux1.fr/ [PARI/GP] `