Jack Brennen on Wed, 24 Apr 2013 01:38:07 +0200

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

Re: Surprising behaviour of sqrt() on squares of integers

I thought that the behavior was that sqrt() of a non-negative integer or real returns a real, and sqrtint() of a non-negative integer
returns an integer.  Both of your examples work fine with sqrtint():

? Mod(5,sqrtint(9))
Mod(2, 3)
? sqrtint(2^256)
? 2^128

On 4/23/2013 4:31 PM, Richard in Reading wrote:
This is just a toy example but there are other real situation where it's annoying that PARI doesn't recognize when you want to take a square root of the square of an integer and return an integer.

Is there some justification for this or is it worth me reporting it as a bug.

  ? Mod(5,sqrt(9))
   ***   at top-level: Mod(5,sqrt(denominat
   ***                 ^--------------------
   *** Mod: forbidden division t_INT % t_REAL.
   ***   Break loop: type 'break' to go back to GP

? sqrt(2^256)
%17 = 3.4028236692093846346337460743176821146 E38
? 2^128
%18 = 340282366920938463463374607431768211456

The above should return the same value in my opinion.

Richard Heylen