Zak Seidov on Sun, 17 Jul 2016 13:03:28 +0200


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

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


OK, I understand, that sometimes floor is wrong.
But plz  help to write a code for computing perfect power number
next to given n (which itself is ppn).
Checking each number n+1,n+2,..etc is too slow code
(for very large n's)..
Thx,
Zak


Воскресенье, 17 июля 2016, 13:14 +03:00 от Karim Belabas <Karim.Belabas@math.u-bordeaux.fr>:

* 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]
`