https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114877

--- Comment #3 from Lénárd Szolnoki <leni536 at gmail dot com> ---
(In reply to Richard Biener from comment #2)
> The standard says the results are unspecified, it doesn't say *p is written
> to,
> so I'm not sure there's a bug here.

C17 (N2176) says in the library section:

"The frexp functions break a floating-point number into a normalized fraction
and an integral power of 2. They store the integer in the int object pointed to
by exp."

"If value is not a floating-point number or if the integral power of 2 is
outside the range of int, the results are unspecified. Otherwise, the frexp
functions return the value x, such that x has a magnitude in the interval [1/2,
1) or zero, and value equals x × 2*exp . If value is zero, both parts of
the result are zero."

This might be a little bit ambiguous, but my reading is that an int value is
always stored, but sometimes the "results are unspecified", where I assume
"results" refer to the fractional part and the integer exponent. An unspecified
result then is stored to the object pointed to by exp.

However further down in Annex F (relevant for targets with IEC 60559, such as
x86_64):

"frexp(±∞, exp) returns ±∞, and stores an unspecified value in the object
pointed to by exp."

"frexp(NaN, exp) stores an unspecified value in the object pointed to by exp
(and returns a NaN)."

This is a lot less ambiguous.

Reply via email to