In libm, sin(qNaN) doesn't expect FE_INVALID ?

Joseph Myers joseph@codesourcery.com
Thu Sep 3 17:03:08 GMT 2020


On Thu, 3 Sep 2020, Ruinland ChuanTzu Tsai wrote:

> Hi all,
> sorry for the bothering.
> 
> Recently, as I'm testing some modification on libm, I happen to realize
> the fact that glibc's testsutie doesn't expect sin(+-qNaN) to trigger
> FE_INVALID, which is designed in `math/libm-test-sin.inc` :

See subclause 6.2 of IEEE 754: "Every general-computational and 
quiet-computational operation involving one or more input NaNs, none of 
them signaling, shall signal no exception, except fusedMultiplyAdd might 
signal the invalid operation exception (see 7.2).".

The special rule about fma(0, Inf, qNaN) (where the standard leaves 
unspecified whether the NaN operand takes precedence over the 
multiplication 0 * Inf that would raise "invalid" if not fused with an 
addition) is handled through INVALID_EXCEPTION_OK in libm-test-fma.inc.  
The cases of INVALID_EXCEPTION_OK for various complex functions are where 
Annex G in the C standard mentions an optional "invalid" exception, and 
those for the significand function are empirical, reflecting that that 
function is not part of any standard.  No function from any standard 
should be using INVALID_EXCEPTION_OK in the testsuite without explicit 
standard wording about such an exception being permitted but optional.

Note that conversions from floating-point formats to *integer* formats 
signal "invalid" for quiet NaN inputs, since the NaN can't be represented 
in the output format.  Likewise, some but not all comparison operations 
signal "invalid" for quiet NaN arguments (see subclause 5.8 of IEEE 754).

-- 
Joseph S. Myers
joseph@codesourcery.com


More information about the Libc-alpha mailing list