2

I am surprised by some of the values returned when comparing Inf and -Inf with NA_real_.

Specifically:

NA_real_ <= Inf
#[1] NA
-Inf <= NA_real_
#[1] NA

The first sentence of the documentation for NA (help(NA)) is

NA is a logical constant of length 1 which contains a missing value indicator.

I suppose there must be some values which are not less than or equal to Inf and some values that are not greater than or equal to -Inf. What are those values? How do you represent them in R? Please provide a complete list.

I am somewhat familiar with NaN's, but don't these arise out of computations that produce results that are simply out of the range of proper values that a double can store? I don't know what Inf - Inf is, exactly, but it can't be greater than Inf. What's bigger than Inf in the IEEE standard that double is supposed to implement? Does that standard simply define that any operation involving NaN returns NaN? Then why doesn't R return NaN? NA is not an IEEE 754 value, is it? Maybe I am misreading the documentation?

Ana Nimbus
  • 635
  • 3
  • 16

1 Answers1

2

The places to point you to are:

?Arithmetic
?Inf
?`>`

The first indicates that IEEE 754 is generally used:

R is dependent on OS services (and they on FPUs) for floating-point arithmetic. On all current R platforms IEC 60559 (also known as IEEE 754) arithmetic is used, but some things in those standards are optional. In particular, the support for denormal numbers (those outside the range given by .Machine) may differ between platforms and even between calculations on a single platform.

And the second indicates that arithmetic with infinity should "work":

In R, basically all mathematical functions (including basic Arithmetic), are supposed to work properly with +/- Inf and NaN as input or output.

However, the third indicates that any logical comparison involving NA returns NA:

Missing values (NA) and NaN values are regarded as non-comparable even to themselves, so comparisons involving them will always result in NA.

So the issue is not that something is "larger" than Inf, but rather than R returns a missing value when you call a comparison with a missing value.

DanY
  • 5,920
  • 1
  • 13
  • 33
  • Re "any logical comparison involving `NA` returns `NA`:" `is.finite(NA_real_)` returns `FALSE` (not `NA`). If this is not a logical comparison, in what category does it fall (per the logic of R)? I'm trying to find a pattern of logic so that I don't have to look these things up every time I need to know them. – Ana Nimbus Apr 02 '19 at 20:14