Re: NaNs
Tom ha scritto:
First, am I correct that NaNs are NOT trap values, that is reading a NaN
itself (but not using it in an arithmetic expression) does not
automatically yield UB?
There are "quiet" NaNs and "signaling" NaNs. The latter are trap values.
A platform may have either, both or none of the two types of NaNs.
I guess the following snippet below is OK, correct?:
double X = std::numeric_limits<double>::quiet_NaN();
// some code
if (X == std::numeric_limits<double>::quiet_NaN())
...
else
...
It's not ok, because a NaN always compare false with any floating point
value, including itself. In fact a NaN can easily be detected by the
expression (x == x) == false. However, it's better (for several reasons)
to use the library provided function isnan().
Second, 18.2.1.2 of the C++-Standard describes some utility-functions of
numeric_limits, including NaN related. The (non-normative) note to these
functions says "required by LIA-1". Please, what is LIA-1. And moreover,
For LIA-1, see http://en.wikipedia.org/wiki/ISO/IEC_10967 which includes
link to download the paper.
how shall I read that note practically speaking? Although the note is of
course non-normative, can I interpret it in a way that practically every
realized platform will offer me NaNs for float, double and long double ?
No, it just says that: LIA-1 requires those features. The standard does
not require an implementation to implement LIA-1, so those feature may
or may not be present.
Third, are there any intended changes to NaNs in the upcoming version of
the Standard?
I don't think so.
HTH,
Ganesh
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]