[Haskell-cafe] Exception for NaN

Richard O'Keefe ok at cs.otago.ac.nz
Tue May 17 00:41:52 CEST 2011


On 16/05/2011, at 7:39 PM, Ketil Malde wrote:

> I'm not intimately familiar with IEEE 754, but in any case we'd be in
> good company: R typically lets you select to sort NaNs as greater or
> less than any other values, and sorts non-NaN values correctly also in
> the presence of NaNs, I think.

> sort(c(3,1,0/0,4,9))
[1] 1 3 4 9

The default behaviour is that missing (NA) and NaN values disappear
from the result.  There is a keyword parameter
"na.last for controlling the treatment of NAs.
If TRUE, missing values in the data are put last;
if FALSE, they are put first; if NA, they are removed."
The default value is NA.

This is *not* a global property of comparison, it is specifically
a run-time option of the "sort" function and the closely related
"order" function, which returns a permutation vector.

It is perfectly possible to provide such a feature in a specific
function without violating the IEEE standard in any way, e.g.

[x | x <- ys, isNaN x] ++ sort [x | x <- ys, not (isNaN x)]





More information about the Haskell-Cafe mailing list