On Thu, Apr 1, 2010 at 11:03 AM, Henrik Bengtsson <[hidden email]> wrote:
> I found in a bit of code the following test for infinity:
> if (x == Inf) ...
> Is that valid, or should it be (as I always thought):
> if (is.infinite(x)) ...?
> Does it depend on whether 'x' is float or integer?
> My question is related to testing for missing values where is.na(x) is required.
Well, '-Inf' is infinite too:
but is not equal to Inf:
> Inf == -Inf
Also, ?is.infinite says it is a generic method, so is.infinite(x)
could be doing anything, depending on x. I would say the best way of
testing if x is a numeric value of plus infinity would be to test
Also also, is.infinite (on a numeric vector) returns FALSE on NA, and
NaN, whereas x==Inf returns NA values for non nice-number inputs.