[EMAIL PROTECTED] writes:

> As people have already suggested, inexact representation.
> 
> 2.45 is being represented as 2.4500000000000002 on my system when printed
> out from the C code in fround.  It is not a binary fraction and so cannot
> be represented exactly (in standard hardware).  The calculation does (2.45
> - 2)*10 and rounds it, and that is just greater than 4.5 (which could be
> represented exactly).
> 
> Try this:
> 
> > x <- 2.45
> > (100*x - 245)
> [1] 2.842171e-14
> 
> which is fairly firm evidence that the representation error is positive, 
> as multiplication by 100 should be exact.  Note though that the print 
> routine will multiply by powers of 10 so the only sure way is to read the 
> bit pattern and compute exactly from that.

Ah, I see now. What I saw before was 

        ltmp = x + 0.5;
        /* implement round to even */
        if(fabs(x + 0.5 - ltmp) < 10*DBL_EPSILON
           && (ltmp % 2 == 1)) ltmp--;
        tmp = ltmp;

but that code sits inside

#ifdef USE_BUILTIN_RINT

and if that's not on we get the system rint() which very likely
will not care about using fuzz.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - ([EMAIL PROTECTED])             FAX: (+45) 35327907

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

Reply via email to