Karim Belabas on Sun, 17 Jul 2016 12:15:05 +0200


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

Re: floor(121^(1/2))=10(??)


* Zak Seidov [2016-07-17 10:02]:
[...]
> (10:59) gp > floor(121^(1/2))
> %1 = 10

This is expected.

* 121^(1/2) is replaced by a floating point approximation. This is
  accurate to 1 ulp of relative accuracy so any element of [10.9999...9,
  11.000...1] is an acceptable result. (This is a white lie: internally, 
  we work in base 2, not 10.)

* the (non-continuous) floor() function is applied to that approximation. 
  Depending on the accuracy and the multiprecision kernel you may get
  either of 10 or 11.

floor() and ceil() are quite unreliable with floating point quantities;
round() is OK provided the result is known to be an integer, and
approximated to sufficient accuracy.

If you want a reliable algebraic test, use
  issquare(121, &t);
or more generally, ispower(). Then t is guaranteed to be the expected
integer.

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-bordeaux.fr/~kbelabas/
F-33405 Talence (France)       http://pari.math.u-bordeaux.fr/  [PARI/GP]
`