Discussion:
[svn:parrot] r36057 - in trunk: . config/auto config/auto/format config/gen/config_h include/parrot src t/compilers/imcc/syn t/op
(too old to reply)
Nicholas Clark
2009-01-27 18:58:43 UTC
Permalink
- gen_sprintf_call(tc, &info, ch);
- ts = cstr2pstr(tc);
+ /* check for Inf and NaN values */
+ if (thefloat == PARROT_FLOATVAL_INF_POSITIVE) {
+ ts = cstr2pstr(PARROT_CSTRING_INF_POSITIVE);
+ }
+ else if (thefloat == PARROT_FLOATVAL_INF_NEGATIVE) {
+ ts = cstr2pstr(PARROT_CSTRING_INF_NEGATIVE);
+ }
+ /* XXX for some reason, this comparison isn't working
+ else if (thefloat == PARROT_FLOATVAL_NAN_QUIET) {
No, it is working :-)

NaN != NaN.

Hence why <=> has 4 possible return values.
+ ts = cstr2pstr(PARROT_CSTRING_NAN_QUIET);
+ }
+ */
+ else if (thefloat != thefloat) {
The above is the valid test for a NaN.

Note, Intel chose that the default optimiser setting on their compiler should
be buggy. (Advice from Klortho #11912). The perl 5 Linux hints file suggests
that one needs to add -we147 to enable correct floating point behaviour.

The best test that I'm aware of for "is it NaN or Inf?" is val != val * 0;
Then, NaN is val != val, +Inf is val > 0, -Inf is val < 0;

Nicholas Clark
Jerry Gay
2009-01-27 23:04:48 UTC
Permalink
Post by Nicholas Clark
- gen_sprintf_call(tc, &info, ch);
- ts = cstr2pstr(tc);
+ /* check for Inf and NaN values */
+ if (thefloat == PARROT_FLOATVAL_INF_POSITIVE) {
+ ts = cstr2pstr(PARROT_CSTRING_INF_POSITIVE);
+ }
+ else if (thefloat == PARROT_FLOATVAL_INF_NEGATIVE) {
+ ts = cstr2pstr(PARROT_CSTRING_INF_NEGATIVE);
+ }
+ /* XXX for some reason, this comparison isn't working
+ else if (thefloat == PARROT_FLOATVAL_NAN_QUIET) {
No, it is working :-)
NaN != NaN.
Hence why <=> has 4 possible return values.
+ ts = cstr2pstr(PARROT_CSTRING_NAN_QUIET);
+ }
+ */
+ else if (thefloat != thefloat) {
The above is the valid test for a NaN.
Note, Intel chose that the default optimiser setting on their compiler should
be buggy. (Advice from Klortho #11912). The perl 5 Linux hints file suggests
that one needs to add -we147 to enable correct floating point behaviour.
The best test that I'm aware of for "is it NaN or Inf?" is val != val * 0;
Then, NaN is val != val, +Inf is val > 0, -Inf is val < 0;
thanks! patched up in r36071 and r36072.
~jerry
Andy Dougherty
2009-01-28 02:14:27 UTC
Permalink
Post by Nicholas Clark
+ else if (thefloat != thefloat) {
The above is the valid test for a NaN.
Note, Intel chose that the default optimiser setting on their compiler should
be buggy. (Advice from Klortho #11912). The perl 5 Linux hints file suggests
that one needs to add -we147 to enable correct floating point behaviour.
The best test that I'm aware of for "is it NaN or Inf?" is val != val * 0;
Then, NaN is val != val, +Inf is val > 0, -Inf is val < 0;
Well, if they are available, isnan() and isinf() are probably worth
trying. You can piggy back on perl 5's $Config{d_isnan} and
$Config{d_isinf}. To distinguish +NaN from -NaN, I suspect you might also
want to use signbit() (which, alas, perl 5 doesn't probe for).

Some of these functions might only be available under certain compiler
options or with certain extra libraries, depending on how a particular
system attempts to adhere to different standards, but it's probably worth
trying them.
--
Andy Dougherty ***@lafayette.edu
Loading...