Board index » delphi » Floating point exceptions

Floating point exceptions

Hallo to all,
I have this problem: I want to know when for some reason I made operations
with invalid floating point numbers:
This is a pseudo code:
double dNan = #Nan;
double f = 10/dNan + 2; //I want floating point exception to be raised here!

so what I do know is this
double dNan;
memset(&dNan, 0xff, sizeof dNan); //This is the only way I know to
explicitly make a double to be Nan
double f = 10/dNan + 2; //But nothing happens

Please tell me how I can do this. I tried with _control87 function, but
didn't succeed, maybe I do not know how to use it.

Regards,
Boris
Boris.Vido...@sirma.bg

 

Re:Floating point exceptions


Quote
Boris Vidolov wrote:

> Hallo to all,

And to you, and to your sirma colleagues who have given so much help here.

Quote
> I have this problem: I want to know when for some reason I made operations
> with invalid floating point numbers:
> This is a pseudo code:
> double dNan = #Nan;
> double f = 10/dNan + 2; //I want floating point exception to be raised here!

> so what I do know is this
> double dNan;
> memset(&dNan, 0xff, sizeof dNan); //This is the only way I know to
> explicitly make a double to be Nan
> double f = 10/dNan + 2; //But nothing happens

0x0FFFFFFFFFFFFFFFF is a quiet NaN.
You want a signaling NaN.

Try this:
  double dNan = std::numeric_limits<double>::signaling_NaN();

Here is a good reference:
  http://developer.intel.com/design/intarch/techinfo/pentium/fpu.htm#9786
Here is a more general one:
  http://babbage.cs.qc.edu/courses/cs341/IEEE-754references.html

Re:Floating point exceptions


Yes, that is the perfect answer!!!

What I am proud of myself is that in the weekend at my home computer I
eventually came across that technique in MSDN, as I have only MS VC++ 6.0 at
home. So experimenting the MS compiler I found out that they have written it
very stupidly: first signals of type SIGFPE do nothing by default; second if
you set your signal handler, it is invoked when division by zero occurs, but
not while using signaling Nan, so what is the "signaling" in their compiler?

    Borland, as I saw today coming at work, have done brilliantly.
    As I was using MSVC yesterday I even thought about writing a class
_double with overloaded arithmetical operators and operator double, all of
them checking for _isnan, I even wrote that class for myself.
    Hopefully it may be not needed.

    Thanks for your knowledge Greg.

Regards,
Boris

Quote
"Greg Chicares" <chica...@mindspring.com> wrote in message

news:3BF74A76.442D9ADD@mindspring.com...
Quote
> Boris Vidolov wrote:

> > Hallo to all,

> And to you, and to your sirma colleagues who have given so much help here.

> > I have this problem: I want to know when for some reason I made
operations
> > with invalid floating point numbers:
> > This is a pseudo code:
> > double dNan = #Nan;
> > double f = 10/dNan + 2; //I want floating point exception to be raised
here!

> > so what I do know is this
> > double dNan;
> > memset(&dNan, 0xff, sizeof dNan); //This is the only way I know to
> > explicitly make a double to be Nan
> > double f = 10/dNan + 2; //But nothing happens

> 0x0FFFFFFFFFFFFFFFF is a quiet NaN.
> You want a signaling NaN.

> Try this:
>   double dNan = std::numeric_limits<double>::signaling_NaN();

> Here is a good reference:
>   http://developer.intel.com/design/intarch/techinfo/pentium/fpu.htm#9786
> Here is a more general one:
>   http://babbage.cs.qc.edu/courses/cs341/IEEE-754references.html

Other Threads