[fpc-pascal] math with infinity and NaN

James Richters james at productionautomation.net
Thu Jun 21 14:58:47 CEST 2018


>For operations producing results in floating-point format, the default result of an operation that 
>signals the invalid operation exception shall be a quiet NaN that should provide some diagnostic 
>information (see 6.2).

If it shall be a quiet NaN doesn't that mean it would never cause the runtime error?   To my understating signaling NaN raises the exception, and Quiet Nan does not.. it just quietly sets the variable to NaN and continues by default.   
It states that the DEFAULT result shall be this quiet NaN so if that's the case then setting SetExceptionMask([exInvalidOp]); should not be required to prevent the runtime error.  The default behavior should be that it's a Quiet NaN.


-----Original Message-----
From: fpc-pascal [mailto:fpc-pascal-bounces at lists.freepascal.org] On Behalf Of gtt at wolfgang-ehrhardt.de
Sent: Wednesday, June 20, 2018 3:42 AM
To: fpc-pascal at lists.freepascal.org
Subject: Re: [fpc-pascal] math with infinity and NaN

This is compatible with IEEE-754.  Section 7.2 says

<quote>
7.2 Invalid operation

For operations producing results in floating-point format, the default result of an operation that signals the invalid operation exception shall be a quiet NaN that should provide some diagnostic information (see 6.2).
These operations are:

...
b) multiplication: multiplication(0, ∞) or multiplication(∞, 0)

...

d) addition or subtraction or fusedMultiplyAdd: magnitude subtraction  
of infinities, such as:
addition(+∞, −∞)

e) division: division(0, 0) or division(∞, ∞)

...

g) squareRoot if the operand is less than zero
</quote>

You get the expected quite NaN results if you add the line

SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide,  
exOverflow, exUnderflow, exPrecision]);

to your test programs.

_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal



More information about the fpc-pascal mailing list