This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [RFC][BZ #15799] Make div cross-platform.
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: "Joseph S. Myers" <joseph at codesourcery dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Fri, 25 Oct 2013 22:40:52 +0200
- 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>
On Fri, Oct 25, 2013 at 08:19:56PM +0000, Joseph S. Myers wrote:
> On Fri, 25 Oct 2013, Ondrej Bilka wrote:
>
> > On Fri, Oct 25, 2013 at 08:09:20PM +0000, Joseph S. Myers wrote:
> > > On Fri, 25 Oct 2013, Ondrej Bilka wrote:
> > >
> > > > Hi, following bug report complains that division does not satisfy c
> > > > standard.
> > >
> > > The bug report is about code that can never be executed - that is, the
> > > logic errors in it are of no significance. Everything after the
> > > assignments to result.quot and result.rem, except for the return
> > > statement, should just be deleted as irrelevant given C99 semantics for
> > > division, and those assignments should be left unchanged. This should be
> > > done for all of div, ldiv and lldiv. This code is not shared with gnulib,
> > > so random C90 compilers are irrelevant to it.
> > >
> > Then close that bug as invalid.
>
> It's a perfectly valid bug report of useless and confusing code in the
> glibc source code, just like a report of spelling errors in the sources is
> valid. I agree with the statement in the bug that "This means that
Got confused by that comment.
> div(numer, denom) should simply return the results of numer / denom and
> numer % denom directly (C99 section 7.20.6.2), and the old incomplete
> run-time test-and-adjustment code (and the obsolete comment block) should
> be removed entirely.". It simply isn't *user-visible* (which means (a) no
> need to add testcases when fixing it, (b) if it hadn't already been
> reported in
Following fixes that.
[BZ #15799]
* stdlib/div.c (div): Remove obsolete code.
* stdlib/ldiv.c (ldiv): Remove obsolete code.
* stdlib/lldiv.c (lldiv): Remove obsolete code.
diff --git a/stdlib/div.c b/stdlib/div.c
index 44a30a7..0f5569a 100644
--- a/stdlib/div.c
+++ b/stdlib/div.c
@@ -59,27 +59,5 @@ div (numer, denom)
result.quot = numer / denom;
result.rem = numer % denom;
- /* The ANSI standard says that |QUOT| <= |NUMER / DENOM|, where
- NUMER / DENOM is to be computed in infinite precision. In
- other words, we should always truncate the quotient towards
- zero, never -infinity. Machine division and remainer may
- work either way when one or both of NUMER or DENOM is
- negative. If only one is negative and QUOT has been
- truncated towards -infinity, REM will have the same sign as
- DENOM and the opposite sign of NUMER; if both are negative
- and QUOT has been truncated towards -infinity, REM will be
- positive (will have the opposite sign of NUMER). These are
- considered `wrong'. If both are NUM and DENOM are positive,
- RESULT will always be positive. This all boils down to: if
- NUMER >= 0, but REM < 0, we got the wrong answer. In that
- case, to get the right answer, add 1 to QUOT and subtract
- DENOM from REM. */
-
- if (numer >= 0 && result.rem < 0)
- {
- ++result.quot;
- result.rem -= denom;
- }
-
return result;
}
diff --git a/stdlib/ldiv.c b/stdlib/ldiv.c
index 76d474f..a03057f 100644
--- a/stdlib/ldiv.c
+++ b/stdlib/ldiv.c
@@ -27,27 +27,5 @@ ldiv (long int numer, long int denom)
result.quot = numer / denom;
result.rem = numer % denom;
- /* The ANSI standard says that |QUOT| <= |NUMER / DENOM|, where
- NUMER / DENOM is to be computed in infinite precision. In
- other words, we should always truncate the quotient towards
- zero, never -infinity. Machine division and remainer may
- work either way when one or both of NUMER or DENOM is
- negative. If only one is negative and QUOT has been
- truncated towards -infinity, REM will have the same sign as
- DENOM and the opposite sign of NUMER; if both are negative
- and QUOT has been truncated towards -infinity, REM will be
- positive (will have the opposite sign of NUMER). These are
- considered `wrong'. If both are NUM and DENOM are positive,
- RESULT will always be positive. This all boils down to: if
- NUMER >= 0, but REM < 0, we got the wrong answer. In that
- case, to get the right answer, add 1 to QUOT and subtract
- DENOM from REM. */
-
- if (numer >= 0 && result.rem < 0)
- {
- ++result.quot;
- result.rem -= denom;
- }
-
return result;
}
diff --git a/stdlib/lldiv.c b/stdlib/lldiv.c
index d1202bf..0da1a6a 100644
--- a/stdlib/lldiv.c
+++ b/stdlib/lldiv.c
@@ -30,27 +30,5 @@ lldiv (numer, denom)
result.quot = numer / denom;
result.rem = numer % denom;
- /* The ANSI standard says that |QUOT| <= |NUMER / DENOM|, where
- NUMER / DENOM is to be computed in infinite precision. In
- other words, we should always truncate the quotient towards
- zero, never -infinity. Machine division and remainer may
- work either way when one or both of NUMER or DENOM is
- negative. If only one is negative and QUOT has been
- truncated towards -infinity, REM will have the same sign as
- DENOM and the opposite sign of NUMER; if both are negative
- and QUOT has been truncated towards -infinity, REM will be
- positive (will have the opposite sign of NUMER). These are
- considered `wrong'. If both are NUM and DENOM are positive,
- RESULT will always be positive. This all boils down to: if
- NUMER >= 0, but REM < 0, we got the wrong answer. In that
- case, to get the right answer, add 1 to QUOT and subtract
- DENOM from REM. */
-
- if (numer >= 0 && result.rem < 0)
- {
- ++result.quot;
- result.rem -= denom;
- }
-
return result;
}