From: Fred P. <fp...@us...> - 2007-01-09 01:57:30
|
Tom Cole wrote: > A little update, while some of you are scratching your heads and wondering "what IS he babbling about? NaNs are just ignored or propagated, aren't they?" > > It turns out this is likely just my problem, since my callers (of Vulcan in embedded mode) have changed the process state to make NaN operations throw exceptions more aggressively on Windows. Cans open, worms everywhere. > > I'd still be delighted for pointers to standards that might guide me in ensuring that I don't break any existing assumptions about NaNs, though, while I muddle through this. > > Thanks. > ...[snip] Hi Tom, If this is still an issue, you might have a look at the <math.h> comparison macros, specified by C99/POSIX/etc, to see if they'll suit your needs. On some platforms, these macros may map to a few inline CPU instructions. Here is a excerpt of the "isgreater" MAN page from an openSUSE 10.2 system: ... The normal relation operations (like less) will fail if one of the operands is NaN. This will cause an exception. To avoid this, C99 defines these macros. The macros are guaranteed to evaluate their operands only once. The operand can be of any real floating-point type. isgreater() determines (x) > (y) without an exception if x or y is NaN. isgreaterequal() determines (x) >= (y) without an exception if x or y is NaN. ... isunordered() is true if x or y is NaN and false otherwise. NOTE Not all hardware supports these functions, and where it doesn't, they will be emulated by macros. This will give you a performance penalty. Don't use these functions if NaN is of no concern for you GLIBC, at least, redefines these macros as optimized assembler instructions for many of the architectures it supports, but not all. Other architectures fall back to using the GCC provided builtin functions for their implementation. I think if you look in <bits/mathinline.h> in your GLIBC installation, you should be able to see if there are optimized assembler versions of these macros for your target platform. These macros are also supported by SunOS 5.10. I don't know if MS/Windows compilers support these "standard" macros, but since the word "standard" is involved, I doubt it. ;-) ;-) ;-) Regards, ---Fred P. |