[Cfp-interest] Not trigger sNaN

Jim Thomas jaswthomas at sbcglobal.net
Sun Sep 16 16:47:31 PDT 2018



> On Aug 28, 2018, at 7:16 PM, Fred J. Tydeman <tydeman at tybor.com> wrote:
> 
> On Tue, 28 Aug 2018 13:13:45 -0500 Rajan Bhakta wrote:
>> 
>>         *AI*: Fred: See which other functions have the need to not 
>> trigger signaling nans but are functions (need to be macros).
> 
> 754 Operations that shall not trigger an sNaN (signal invalid):
> 
> "*" are functions in C
> 
> copy() = memcpy()*, memmove()* via pointers
> negate()

F.3#4 in P1 says "The unary - operator raises no floating-point exceptions, even if the operand is a signaling NaN."

> abs() = fabs()*

F.10.4.2#2 in P1 says "fabs(x) raises no floating-point exceptions, even if x is a signaling NaN."

> copySign() = copysign()*

F.10.8.1#2 in P1 says "copysign(x, y) raises no floating-point exceptions, even if x or y is a signaling NaN."

> 
> encodeDecimal() = encodedec()* via pointers
> decodeDecimal() = decodedec()* via pointers
> encodeBinary() = encodebin()* via pointers
> decodeBinary() = decodebin()* via pointers
> 
> class() = fpclassify()
> isSignMinus() = signbit()
> isNormal() = isnormal()
> isFinite() isfinite()
> isZero() = iszero()
> isSubnormal() = issubnormal()
> isInfinite() = isinf()
> isNaN() = isnan()
> isSignaling() = issignaling()
> isCanonical() = iscanonical()

F.3#5 in P1 says "The C classification macros fpclassify, iscanonical, isfinite, isinf, isnan, isnormal, issignaling, issubnormal, and iszero provide the IEC 60559 operations indicated in the table above provided their arguments are in the format of their semantic type. Then these macros raise no floating-point exceptions, even if an argument is a signaling NaN.”

> radix()
> totalOrder() = totalorder()*
> totalOrderMag() =totalordermag()*
> 
> sameQuantum() = samequantum()*
> 
> getPayload() = getpayload()* via pointer
> setPayload() = setpayload()* via pointer
> setPayloadSignaling() = setpayloadsig()* via pointer
> 
> 754 Operations that should not trigger an sNaN:
> 
> fp->char = printf()*

754 (5.12.1) gives the options of returning “snan" and not signaling or returning “nan" and signaling.

P1 says "Append to the end of F.5 the following paragraph:

[4] The fprintf family of functions in <stdio.h> and the fwprintf family of functions in <wchar.h> should behave as if floating-point operands were passed through the canonicalize function of the same type.

In F.5#4, attach a footnote to the wording:

The fprintf family of functions in <stdio.h> and the fwprintf family of functions in <wchar.h> should behave as if floating-point operands were passed through the canonicalize function of the same type.

where the footnote is:

*) This is a recommendation instead of a requirement so that implementations may choose to print signaling NaNs differently from quiet NaNs.”

> char->fp = scanf()* via pointer

754 (5.12.1) says "Conversion of an external character sequence “snan” (regardless of case) with an optional preceding sign, to a supported format should either produce a signaling NaN or else produce a quiet NaN and signal the invalid operation exception.”

CFP doesn’t support “snan”.

> 
> 
> Given that some of the above are done (in C) as macros and others as
> functions, implementations may have to use macros for the functions
> and compiler magic to avoid triggering an sNaN.  Not sure how well
> that will work for function pointers or type generic macros.
> 
> Another idea is a special calling convention that avoids triggering an
> sNaN.

Yes, implementations do have ways of dealing with this.

> 
> Whatever is used, it should work for constants, variables, and
> expressions.
> 
> The functions without pointers are:
> fabs()
> copysign()
> totalorder()
> totalordermag()
> samequantum()
> printf()
> 
> 
> 
> ---
> Fred J. Tydeman        Tydeman Consulting
> tydeman at tybor.com      Testing, numerics, programming
> +1 (702) 608-6093      Vice-chair of PL22.11 (ANSI "C")
> Sample C99+FPCE tests: http://www.tybor.com
> Savers sleep well, investors eat well, spenders work forever.
> 
> _______________________________________________
> Cfp-interest mailing list
> Cfp-interest at oakapple.net
> http://mailman.oakapple.net/mailman/listinfo/cfp-interest




More information about the Cfp-interest mailing list