[Cfp-interest 3101] Re: Issue: frexp and double-double underflow
Fred J. Tydeman
tydeman at tybor.com
Tue Apr 23 21:56:50 PDT 2024
On Tue, 23 Apr 2024 17:47:08 -0400 Hubert Tong wrote:
>
>frexp is not specified to have any failure conditions, but it necessarily
>will fail to return the specified values for some double-double inputs.
>
>The following program will fail on the second assertion due to underflow in
>the less significant component of the double-double value.
>#include <assert.h>
>#include <math.h>
>#include <float.h>
>int main() {
> int exp;
> const long double oneplus = 1.L + DBL_TRUE_MIN;
> const long double frac = frexp(oneplus, &exp);
> assert(exp == 1);
> assert(frac * 2 == oneplus);
>}
In this case, frexp() returns 0.5 + DBL_TRUE_MIN/2
That value is not an underflow.
Just because part of the value is smaller than DBL_TRUE_MIN,
does not make it an underflow.
It is no different than frexp( DBL_TRUE_MIN*2.2, &exp);
which returns DBL_TRUE_MIN*1.1 (which is not underflow)
Aside: int exp; is a name clash with exp() in <math.h>
---
Fred J. Tydeman Tydeman Consulting
tydeman at tybor.com Testing, numerics, programming
+1 (702) 608-6093 Vice-chair of INCITS/C (ANSI "C")
Sample C17+FPCE tests: http://www.tybor.com
Savers sleep well, investors eat well, spenders work forever.
More information about the Cfp-interest
mailing list