This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC][BZ #15799] Make div cross-platform.


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.

       Returns

       [#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
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]