Karim Belabas on Wed, 27 Oct 2021 18:57:09 +0200


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

Re: sqrtint() on non-integer arguments


> On Mon, Oct 25, 2021 at 5:02 PM Max Alekseyev <maxale@gmail.com> wrote:
>> sqrtint() does not accept non-integer arguments such as t_REAL or t_FRAC.
>> I think it'd be helpful if it did so, which is easy to archive by calling
>> floor() before performing actual computation. I believe it used to work
>> like this a while ago, but not anymore.
>>
>> Same applies to sqrtnint().
>
* Charles Greathouse [2021-10-25 23:41]:
> This would be useful to me and should be trivial to implement (a single
> call to gfloor, change gp2c type from int to mp).

Not too hard but not quite trivial because you also want to avoid

? sqrtint(floor(1e40))
  ***   at top-level: sqrtint(floor(1e40))
  ***                         ^------------
  *** floor: precision too low in truncr (precision loss in truncation).

and get instead 

? sqrtint(1e40)
%1 = 100000000000000000000

And you also need to make sure that things like

? sqrtint(9/4,&r)
%2 = 1
? r
%3 = 5/4
? logint(3 + 2*quadgen(17), 3, &r)
%4 = 1
? r
%5 = 3

work as expected.

Anyway, it's done in the 'master' branch for sqrtint / sqrtnint / logint :-)
Please test and report unexpected behaviour !

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 21 23
351, cours de la Liberation    http://www.math.u-bordeaux.fr/~kbelabas/
F-33405 Talence (France)       http://pari.math.u-bordeaux.fr/  [PARI/GP]
`