[Cfp-interest 3309] Re: ERANGE question
Jim Thomas
jaswthomas at sbcglobal.net
Sat Oct 12 14:29:07 PDT 2024
> On Oct 9, 2024, at 5:45 AM, Vincent Lefevre <vincent at vinc17.net> wrote:
>
> On 2024-10-09 09:30:10 +0200, Paul Zimmermann wrote:
>> Hi,
>>
>> I have a question about ERANGE.
>>
>> This question comes from whether x^y should set errno to ERANGE
>> for x=0x1.57fffffffffffp-1005 and y=-0x1.04f352c2db70ep+0
>> (in binary64 and rounding to nearest).
>>
>> We have DBL_MAX < x^y < 2^1024*(1-2^-54), thus with unbounded
>> exponent, x^y rounds to DBL_MAX.
>>
>> N3301 says "a range error occurs if and only if the result overflows or
>> underflows, as defined below".
>
> That's strange. AFAIK, underflows should not be range errors.
>
>> And "A floating result overflows if a finite result value with ordinary
>> accuracy265) would have magnitude (absolute value) too large for the
>> representation with full precision in the specified type."
>>
>> It is not clear to me if this is meant before or after rounding (with
>> unbounded exponent).
>
> "the representation with full precision in the specified type" implies
> that the result is rounded. Otherwise I don't see how this can be
> interpreted.
>
> But I'm wondering why the word "full" is used.
This is intended to accommodate double-double formats that can represent results with huge finite magnitude but not with the full precision of the type, e.g. if both parts of a double-double number are DBL_MAX. Such numbers are beyond the range of C model numbers. Such results are overflows, per definition above.
> Ditto in 6.4.5.3p7
> about floating literals of decimal floating type. Is this because
> some representations are not normalized, thus are regarded as
> having less precision?
>
>> Should errno be set to ERANGE, even if x^y rounds to DBL_MAX?
>
> In rounding to nearest, I would say no.
>
> But for the directed rounding modes, the definition seems wrong.
Note that the definition includes “ordinary accuracy” (defined by the implementation). This is intended to cover IEEE 754 overflow with directed rounding (as well as no nearest).
> One should use the IEEE 754 definition.
Yes. The intention is that an implementation that follows IEEE 754 for floating-point exceptions need only define math_errhandling to MATH_ERREXCEPT to conform to the C treatment of error conditions (7.12.2).
- Jim Thomas
>
> --
> Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
> 100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
> Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
> _______________________________________________
> 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