AdaptableFunctor computes both integral quotient and 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 of the represented ring. 1 In particular, r is chosen to be 0 if possible. Moreover, we require q to be minimized with respect to the proper integer norm.
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 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.
The following table illustrates the behavior for integers:
| - |
|
AdaptableFunctor
AlgebraicStructureTraits::DivMod::result_type | |
Is void.
| |
AlgebraicStructureTraits::DivMod::first_argument_type | |
Is AlgebraicStructureTraits::Type.
| |
AlgebraicStructureTraits::DivMod::second_argument_type | |
Is AlgebraicStructureTraits::Type.
| |
AlgebraicStructureTraits::DivMod::third_argument_type | |
Is AlgebraicStructureTraits::Type&.
| |
AlgebraicStructureTraits::DivMod::fourth_argument_type | |
Is AlgebraicStructureTraits::Type&.
|
result_type |
| |||
computes the quotient q and remainder r, such that x = q*y + r and r minimal with respect to the Euclidean Norm on Type. | ||||
template <class NT1, class NT2> | ||||
result_type | div_mod ( NT1 x , NT2 y , third_argument_type q , fourth_argument_type r ) | |||
This operator is defined if NT1 and NT2 are ExplicitInteroperable with coercion type AlgebraicStructureTraits::Type. |
AlgebraicStructureTraits
AlgebraicStructureTraits::Mod
AlgebraicStructureTraits::Div
1 |
For integers this norm is the absolute value. For univariate polynomials this norm is the degree. |