[R] Precision level
Prof Brian Ripley
ripley at stats.ox.ac.uk
Fri Mar 26 08:22:59 CET 2010
On Fri, 26 Mar 2010, Rolf Turner wrote:
> On 26/03/2010, at 12:38 PM, jim holtman wrote:
>> WHen using '==' or '%in%' it is a equality test -- it has to equal zero. If
>> you want a tolerance in the test, use 'all.equal'
>> On Thu, Mar 25, 2010 at 5:29 PM, Dimitri Liakhovitski <ld7631 at gmail.com>wrote:
>>> I am wondering at what point does R consider a numeric value to be
>>> equal to zero - for statements of the type x==0 and x %in% 0.
>>> Thank you very much!
> There is still perhaps a question to be answered here. One can key in
> a representation of a number, different from ``0'' and yet get a value
> deemed to be 0 by the machine.
> E.g. on my machine
>> 1e-324 == 0
>  TRUE
>> 1e-323 == 0
>  FALSE
> The question of where the line is drawn is probably ill-posed or meaningless
> or something like that. It's not clear to me what the issues are. Also the
> answer, if there is a meaningful one, is likely to be machine dependent rather
> than R dependent.
Nope, for OSes whose runtimes use the IEC 60559 standard (almost all
of them, as these functions are mainly done in the FPU).
The smallest normalized non-zero double is
For numbers smaller than that there is gradual overflow to zero via
The general principle is that when a number if parsed, the closest
representable double is used: and for "1e-324" that is zero.
> Rolf Turner
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help