Skip to content
Prev 344977 / 398500 Next

how to judge a virable is a integer?

It sounds like you want an 'is.integral' function to tell if a
number acts like a mathematical integer, as opposed to
'is.integer', which tells if a number is stored as a 32-bit
computer integer.  The test will depend on what properties
of mathematical integers you are most interested in.

   is.integral <- function (x)  (floor(x) == x) & (abs(x) + 1 > abs(x))
will return TRUE if x has no fractional part and the number's
putative successor (predecessor if negative) is different than
the number.  That latter test is equivalent (roughly) to log2(abs(x))<53 and
comes into play when you run out of bits in the mantissa of
a double precision number.  (One might want it to return NA in
that case, but I think FALSE works better.)


Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Sat, Oct 18, 2014 at 3:41 AM, PO SU <rhelpmaillist at 163.com> wrote: