[cfp-interest 3790] Re: Action item: sign of 0 returned by fromfp
Jerome Coonen
jcoonen at gmail.com
Mon Feb 16 22:04:34 PST 2026
This reply expands on the note below regarding fromfp.
The proposed wording to specify a return of positive or unsigned zero
whenever the return value is zero may break implementations implemented
otherwise, since the original definition of fromfp in C23. The proposal is
broadened to include unsigned zero, when that is relevant.
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 positive or unsigned.
Another issue arises in Table F.2 with its bindings of the 10
convertToIntegerXXXXX operations in 60559. The applications of the four
variants of [u]fromfp[x] are really compositions of a cast (to the integer
type) with the fromfp variant. Here are possible changes:
For convertToIntegerTiesToEven and its three neighbors, from:
fromfp, ufromfp
To:
cast of fromfp or ufromfp
For convertToIntegerTiesToAway, from:
fromfp, ufromfp, lround, llround
To:
lround, llround, cast of fromfp or ufromfp
For convertToIntegerExactTiesToEven and its four neighbors, from:
fromfpx, ufromfpx
To:
cast of fromfpx or ufromfpx
-Jerome Coonen
650.996.4738
jcoonen at gmail.com
On Sat, Feb 14, 2026 at 1:02 PM Jerome Coonen <jcoonen at gmail.com> wrote:
> 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/20260216/6b9f1a37/attachment.htm>
More information about the cfp-interest
mailing list