[cfp-interest 3788] Action item: sign of 0 returned by fromfp
Jerome Coonen
jcoonen at gmail.com
Sat Feb 14 13:02:04 PST 2026
Greetings,
Joseph Myers has raised the issue of the sign of a zero result from the
fromfp family of functions.
> Do the fromfp functions follow the same rules about the sign of a zero
> result as all the other functions rounding to an integer in a floating
> type (i.e., the sign of a zero result is the sign of the floating
> argument)? In particular, is it correct that the ufromfp functions return
> -0 when a negative argument rounds to 0? The issue of the sign of a zero
> result was introduced when we changed these functions to return a floating
> type for C23 (N2548), but we didn't add any text to the standard
> discussing it for these functions.
Both the binary and decimal flavors of fromfp take an unsigned int
parameter width. Depending on the possible prefix 'u', they specify an
integral return value in the floating return type corresponding to an
unsigned or a 2's complement signed binary width-bit integer.
In both unsigned and 2's complement integer representations, zero is
mathematical, without algebraic sign. The natural behavior for fromfp is to
return +0 when it returns zero, regardless of the input argument and choice
of roundings. The integral result of fromfp is the canonical representation
of the integer value in a normalized floating format.
This added wording would clarify the point.
Proposed change to 7.12.10.10p2:
From:
. . . then the functions return the integer value (represented
in floating type).
To:
. . . then the functions return the integer value (represented
in floating type); a zero return value is always +0.
The phrasing is designed to flow into the following conditional text.
-Jerome Coonen
650.996.4738
jcoonen at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.oakapple.net/pipermail/cfp-interest/attachments/20260214/0cf77425/attachment.htm>
More information about the cfp-interest
mailing list