Karim Belabas on Tue, 23 Sep 2014 14:23:25 +0200


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

Re: Non-zero number plus zero is zero?


* 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.

N.B. If you want an equality operator with better properties, use '==='

> which is also inconsistent with:
> 
> gp> 0e1 < 1
> %13 = 1
> gp> 0e1 >= 1
> %17 = 0

problem with cmpir() in both cases, as explained above.

> Do you consider this a bug?

Yes, although possibly not the one you intended to report :-)

Cheers,

    K.B.
--
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]
`