[Rd] equality testing, was all.equal....

ProfJCNash profjcnash at gmail.com
Fri Jul 31 14:18:51 CEST 2015

These issues have been around for many years. I've created some upset
among some programmers by using equality tests for reals (in R doubles).

However, there's a "but", and it is that I test using

  if ( (a + offset) == (b + offset) ) {    }

where offset is a number like 100.0. This is really "equality to a
scale" defined by the offset. It also seems to inhibit those who don't
know what is going on from changing a tolerance. It will, of course, be
defeated by some optimizing compilers.

I started doing this on very small computers (<4K bytes for program and
data) where I wanted to avoid lots of checks on whether a and b were
small. Then I realized it simplified code and is suitable for most tests
of equality.

It may be that an all.equal.offset() function would be useful.

Best, JN

More information about the R-devel mailing list