fixed rounding mode of div to TOWARDS_ZERO,

which is compliant to most implementations of integers.
This commit is contained in:
Michael Hemmer 2007-02-02 12:00:14 +00:00
parent 659bf06d68
commit c59a8c4a2a
1 changed files with 64 additions and 2 deletions

View File

@ -3,7 +3,69 @@
\ccDefinition
\ccc{AdaptableFunctor} computes both integral quotient and remainder
of division with remainder.
of division with remainder. The quotient $q$ and remainder $r$ are computed
such that $x = q*y + r$ and $|r| < |y|$ with respect to the proper integer norm.
\footnote{
For integers this norm is the absolute value.\\
For univariate polynomials this norm is the degree.}
In particular, $r$ is chosen to be $0$ if possible.
For \ccc{RealEmbeddable} \ccc{EuclideanRing}s we require $q$ to be computed
as $x/y$ rounded towards zero.
Note that the last condition is needed to ensure a unique computation of the
pair $(q,r)$. However, an other option is to require minimality for $|r|$,
with the advantage that
a {\em mod(x,y)} operation would return the unique representative of the
residue class of $x$ with respect to $y$, e.g. $mod(2,3)$ should return $-1$.
But this conflicts with nearly all current implementation
of integer types. From there, we decided to stay conform with common
implementations and require $q$ to be computed as $x/y$ rounded towards zero,
for \ccc{RealEmbeddable} \ccc{EuclideanRing}s.
\ignore{
Note that in general the above definition does not force a unique computation
of the pair $(q,r)$. This could be solved by requiring $|r|$ to be minimal,
in particular a {\em mod} operation would return the unique representative of
its residue class. But this conflicts with nearly all current implementation
of integer types. From there, we decided to stay conform with common
implementation and require $q$ to be computed as $x/y$ rounded towards zero,
for \ccc{RealEmbeddable} \ccc{EuclideanRing}s.
}
The following truth table illustrates the behavior for integers:
\begin{tabular}{ccc}
\begin{tabular}{|c|c|c|c|}
\hline
$\ x\ $ & $\ y\ $ & $\ q\ $ & $\ r\ $\\
\hline
3 & 3 & 1 & 0\\
2 & 3 & 0 & 2\\
1 & 3 & 0 & 1\\
0 & 3 & 0 & 0\\
-1 & 3 & 0 & -1\\
-2 & 3 & 0 & -2\\
-3 & 3 & -1 & 0\\
\hline
\end{tabular}
& - &
\begin{tabular}{|c|c|c|c|}
\hline
$\ x\ $ & $\ y\ $ & $\ q\ $ & $\ r\ $\\
\hline
3 & -3 & -1 & 0\\
2 & -3 & 0 & 2\\
1 & -3 & 0 & 1\\
0 & -3 & 0 & 0\\
-1 & -3 & 0 & -1\\
-2 & -3 & 0 & -2\\
-3 & -3 & 1 & 0\\
\hline
\end{tabular}\\
\end{tabular}
\ccRefines