www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Using std.math: FloatingPointControl.enableExceptions

reply Shriramana Sharma <samjnaa_dont_spam_me gmail.com> writes:
Hello. I'm trying to figure out how to use 
FloatingPointControl.enableExceptions. Upon enabling severeExceptions I 
would expect the division by zero to be signaled, but neither do I get a 
SIGFPE nor does ieeeFlags show the exception having been signaled. What am I 
doing wrong?

import std.stdio;
import std.math;
void main()
{
    FloatingPointControl fc;
    fc.enableExceptions(fc.severeExceptions);
    real a = 1.0 / 0.0;
    writeln(ieeeFlags.divByZero);
}

-- 
Shriramana Sharma, Penguin #395953
Dec 10 2015
parent reply rumbu <rumbu rumbu.ro> writes:
On Friday, 11 December 2015 at 06:28:09 UTC, Shriramana Sharma 
wrote:
 Hello. I'm trying to figure out how to use 
 FloatingPointControl.enableExceptions. Upon enabling 
 severeExceptions I would expect the division by zero to be 
 signaled, but neither do I get a SIGFPE nor does ieeeFlags show 
 the exception having been signaled. What am I doing wrong?

 import std.stdio;
 import std.math;
 void main()
 {
     FloatingPointControl fc;
     fc.enableExceptions(fc.severeExceptions);
     real a = 1.0 / 0.0;
     writeln(ieeeFlags.divByZero);
Constant folding: a is evaluated at compile time to + infinity.
Dec 10 2015
parent Shriramana Sharma <samjnaa_dont_spam_me gmail.com> writes:
rumbu wrote:

 Constant folding: a is evaluated at compile time to + infinity.
Hmm... I guess the compiler figures that if someone is hardcoding that expression then they don't want to see an exception. Thanks for the explanation. -- Shriramana Sharma, Penguin #395953
Dec 11 2015