Board index » cppbuilder » Is quiet_NaN supposed to be assignable to another double?

Is quiet_NaN supposed to be assignable to another double?


2005-03-03 02:11:27 PM
cppbuilder24
Do you expect assigning a quiet_NaN to a double should generate an exception at run
time? See comments below.
#include <limits>
double generateNaN()
{
double zz = 0.0/0.0; // this does not generate an exception.
double xx = std::numeric_limits<double::quiet_NaN(); // this generates an exception.
double yy = xx;
// the return does not generate a double but assignment of the function return
where called does generate an error.
return std::numeric_limits<double::quiet_NaN();
}
 
 

Re:Is quiet_NaN supposed to be assignable to another double?

This assignment works under some circumstances:
double xx = std::numeric_limits<double::quiet_NaN();
In other circumstances I get "Project myprog.exe raised exception class EInvalidOp
with message 'Invalid floating point operation'.
The sooner I do that assignment in the execution in my program the more likely it is
to cause an exception. For example, if I do the assignment in the constructor of the
main form then the exception happens. If I do many other things before doing an
operation that causes that assignment to execute then the assignment does not trigger
the exception. I have not been able to narrow down to a particular sequence of steps
that makes the exception no longer happen when the assignment happens.
Somewhere in the initialization of lots of controls something happens that causes
that assignment to be silent. Since some of the code is third party libraries (VCL
controls) and it also does lots of C/C++ RTL calls I'm having a hard time guessing
what might cause the handling of NaN to change.
Any guesses on what causes the difference in what I am seeing? Might there be some
RTL flag that can get set that changes how the RTL handles NaN assignments?
I thought the whole idea of using quiet_NaN is that it is, well, QUIET...
Randall Parker wrote:
Quote
Do you expect assigning a quiet_NaN to a double should generate an
exception at run time? See comments below.

#include <limits>

double generateNaN()
{
double zz = 0.0/0.0; // this does not generate an exception.
double xx = std::numeric_limits<double::quiet_NaN(); // this
generates an exception.
double yy = xx;
// the return does not generate a double but assignment of the
function return where called does generate an error.
return std::numeric_limits<double::quiet_NaN();
}
 

Re:Is quiet_NaN supposed to be assignable to another double?

Hi!
Randall Parker wrote:
Quote
In other circumstances I get "Project myprog.exe raised exception class
EInvalidOp with message 'Invalid floating point operation'.
Is this just the de{*word*81}? Can you resume program execution
without further problems?
Frank
 

{smallsort}

Re:Is quiet_NaN supposed to be assignable to another double?

Frank,
If I run outside of the de{*word*81} then I get a dialog that pops up that says "Invalid
floating point operation" and the code jumps down a different path and does not
continue on the it was on. So, no, can't just let it proceed.
But, again, I can avoid the error if I let a whole large pile of other code run
first. Something in a library (and I'm using a few commercial VCL libs) alters
mathematical exception handling.
I'd really like to know whether assignment of a quiet_NaN is supposed to be
considered a legal operation. If not, what is the point of the "quiet" part of it?
Frank Birbacher wrote:
Quote
Hi!

Randall Parker wrote:

>In other circumstances I get "Project myprog.exe raised exception
>class EInvalidOp with message 'Invalid floating point operation'.


Is this just the de{*word*81}? Can you resume program execution without
further problems?

Frank