This is the mail archive of the
mailing list for the glibc project.
Re: [RFC][BZ #15799] Make div cross-platform.
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Roland McGrath <roland at hack dot frob dot com>
- Cc: OndÅej BÃlka <neleai at seznam dot cz>, <libc-alpha at sourceware dot org>
- Date: Fri, 25 Oct 2013 22:03:49 +0000
- Subject: Re: [RFC][BZ #15799] Make div cross-platform.
- Authentication-results: sourceware.org; auth=none
- References: <20131025182101 dot GD21615 at domone dot podge> <Pine dot LNX dot 4 dot 64 dot 1310252002400 dot 17813 at digraph dot polyomino dot org dot uk> <20131025201557 dot GA8125 at domone dot podge> <Pine dot LNX dot 4 dot 64 dot 1310252016460 dot 17813 at digraph dot polyomino dot org dot uk> <20131025204052 dot GA8314 at domone dot podge> <20131025215050 dot A80D8746B9 at topped-with-meat dot com>
On Fri, 25 Oct 2013, Roland McGrath wrote:
> It's best to leave a comment behind stating explicitly that the old issue
> no longer applies and why. Joseph gave the C99 section reference and
> perhaps can offer a clear comment on the subject.
I think nowadays an extra comment is more likely to confuse people. If
people look to C99 or C11 for what these functions should do, they'll see:
[#2] The div, ldiv, and lldiv, functions compute numer /
denom and numer % denom in a single operation.
[#3] The div, ldiv, and lldiv functions return a structure
of type div_t, ldiv_t, and lldiv_t, respectively, comprising
both the quotient and the remainder. The structures shall
contain (in either order) the members quot (the quotient)
and rem (the remainder), each of which has the same type as
the arguments numer and denom. If either part of the result
cannot be represented, the behavior is undefined.
and they'll see that plainly this is exactly what the functions are doing.
(In C90 the text specifying div and ldiv had to be more complicated
because the specification of the / and % operators had weaker
requirements; C99 aligned the requirements on the operators with the
requirements on these functions.) A statement of the form
/* We can assume C99 semantics for / and %, which match the semantics
of this function. */
would be true, but doesn't seem much more useful here than anywhere else
we assume (of course) that C operators work correctly.
Joseph S. Myers