From b.rowlingson at lancaster.ac.uk  Thu Apr  1 12:21:40 2010
From: b.rowlingson at lancaster.ac.uk (Barry Rowlingson)
Date: Thu, 1 Apr 2010 11:21:40 +0100
Subject: [Rd] Is it valid to do x == Inf?
In-Reply-To: <j2n59d7961d1004010303ja372b671r8da5fc73ca62edb7@mail.gmail.com>
References: <j2n59d7961d1004010303ja372b671r8da5fc73ca62edb7@mail.gmail.com>
Message-ID: <k2xd8ad40b51004010321x5a1f0bcdi619c75103e6f9839@mail.gmail.com>

On Thu, Apr 1, 2010 at 11:03 AM, Henrik Bengtsson <hb at stat.berkeley.edu> wrote:
> Hi,
>
> 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:

 > is.infinite(-Inf)
 [1] TRUE

 but is not equal to Inf:

 > Inf == -Inf
 [1] FALSE

 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
x==Inf.

 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.

Barry

-- 
blog: http://geospaced.blogspot.com/
web: http://www.maths.lancs.ac.uk/~rowlings
web: http://www.rowlingson.com/
twitter: http://twitter.com/geospacedman
pics: http://www.flickr.com/photos/spacedman



[Rd] Is it valid to do x == Inf?
Barry Rowlingson