Bill Allombert on Mon, 30 Sep 2002 12:02:37 +0200


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

Re: Precision lost in truncation


On Sun, Sep 29, 2002 at 06:20:26PM +0200, Thomas Baruchel wrote:
> Brest, le dimanche 29 septembre
> 
> Hi,
> 
> very often I want to use floor(x) in my functions.
> Somtimes, it's ok; sometimes, I have an error:
> "tuncation lost etc.". How can I avoid it ?
> Of course, precision is lost, but it's exactly what
> floor() is meant to do !!!

Floor return the largest integer less than x.
floor(1E100)
  ***   precision too low in mptrunc (precision loss in truncation).
why ?
because with 28 decimal 1E100 is an approximation of every numbers
in the interval [1E100-1E72,1E100+1E72], so floor can only compute the
integer with an error of 1E72, but PARI/GP return only exact value for
integers.

If you are interested in the lower bound of the interval, use truncate instead

lowerbound(x)=local(t,e);t=truncate(x,&e);t-(1<<max(e,0))

Else you must increase the precision to 101 decimal digits.

Cheers,

Bill