[Cfp-interest 2027] Re: FLT_HAS_SUBNORM is 0: what is fpclassify(<subnormal>)?

Steve (Numerics) Canon scanon at apple.com
Wed Jun 16 09:19:18 PDT 2021


> On Jun 15, 2021, at 8:44 PM, David Hough CFP <pcfp at oakapple.net> wrote:
> 
>> I do not know if a negative subnormal would be flushed to -zero or +zero.
> 
> Signs were preserved on the systems I knew about.
> 
>> This matters for (at least):
>  fpclassify()
>  iscanonical()
>  issubnormal()
>  iszero()
>  signbit()
>  nextafter()
>  nexttoward()
>  nextup()
>  nextdown()
> 
> I'd suggest that these kinds of functions ignore the flush mode and 
> identify subnormals properly - the actual arithmetic would do whatever it
> did in nonstandard mode.

There definitely exists some hardware that flushes all subnormals to +0, but it is a distinct minority (at least for CPUs, which generally preserve sign when flushing). Preserving the sign seems like the “obvious” correct choice, but not all HW has done that.

AFAIK no standard offers any real guidance on how to handle the operations Fred listed. I disagree mildly with David, however, and would argue that if you want to have a consistent semantics for flush-to-zero, the only really defensible choice is to treat all subnormals as non-canonical encodings of zero, because that’s how they behave in arithmetic. This is how Swift resolved this question when targeting ARMv7 platforms that always flush, for example (which happily are mostly behind us now).

– Steve


More information about the Cfp-interest mailing list