version 1.1.1.2, 2000/09/09 14:12:18 |
version 1.1.1.3, 2000/12/01 05:44:46 |
Line 26 versions, except that this permission notice may be st |
|
Line 26 versions, except that this permission notice may be st |
|
translation approved by the Foundation. |
translation approved by the Foundation. |
|
|
|
|
|
File: gmp.info, Node: Integer Division, Next: Integer Exponentiation, Prev: Integer Arithmetic, Up: Integer Functions |
|
|
|
Division Functions |
|
================== |
|
|
|
Division is undefined if the divisor is zero, and passing a zero |
|
divisor to the divide or modulo functions, as well passing a zero mod |
|
argument to the `mpz_powm' and `mpz_powm_ui' functions, will make these |
|
functions intentionally divide by zero. This lets the user handle |
|
arithmetic exceptions in these functions in the same manner as other |
|
arithmetic exceptions. |
|
|
|
There are three main groups of division functions: |
|
* Functions that truncate the quotient towards 0. The names of |
|
these functions start with `mpz_tdiv'. The `t' in the name is |
|
short for `truncate'. |
|
|
|
* Functions that round the quotient towards -infinity). The names |
|
of these routines start with `mpz_fdiv'. The `f' in the name is |
|
short for `floor'. |
|
|
|
* Functions that round the quotient towards +infinity. The names of |
|
these routines start with `mpz_cdiv'. The `c' in the name is |
|
short for `ceil'. |
|
|
|
For each rounding mode, there are a couple of variants. Here `q' |
|
means that the quotient is computed, while `r' means that the remainder |
|
is computed. Functions that compute both the quotient and remainder |
|
have `qr' in the name. |
|
|
|
- Function: void mpz_tdiv_q (mpz_t Q, mpz_t N, mpz_t D) |
|
- Function: unsigned long int mpz_tdiv_q_ui (mpz_t Q, mpz_t N, |
|
unsigned long int D) |
|
Set Q to [N/D], truncated towards 0. |
|
|
|
The function `mpz_tdiv_q_ui' returns the absolute value of the true |
|
remainder. |
|
|
|
- Function: void mpz_tdiv_r (mpz_t R, mpz_t N, mpz_t D) |
|
- Function: unsigned long int mpz_tdiv_r_ui (mpz_t R, mpz_t N, |
|
unsigned long int D) |
|
Set R to (N - [N/D] * D), where the quotient is truncated towards |
|
0. Unless R becomes zero, it will get the same sign as N. |
|
|
|
The function `mpz_tdiv_r_ui' returns the absolute value of the |
|
remainder. |
|
|
|
- Function: void mpz_tdiv_qr (mpz_t Q, mpz_t R, mpz_t N, mpz_t D) |
|
- Function: unsigned long int mpz_tdiv_qr_ui (mpz_t Q, mpz_t R, mpz_t |
|
N, unsigned long int D) |
|
Set Q to [N/D], truncated towards 0. Set R to (N - [N/D] * D). |
|
Unless R becomes zero, it will get the same sign as N. If Q and R |
|
are the same variable, the results are undefined. |
|
|
|
The function `mpz_tdiv_qr_ui' returns the absolute value of the |
|
remainder. |
|
|
|
- Function: unsigned long int mpz_tdiv_ui (mpz_t N, unsigned long int |
|
D) |
|
Like `mpz_tdiv_r_ui', but the remainder is not stored anywhere; its |
|
absolute value is just returned. |
|
|
|
- Function: void mpz_fdiv_q (mpz_t Q, mpz_t N, mpz_t D) |
|
- Function: unsigned long int mpz_fdiv_q_ui (mpz_t Q, mpz_t N, |
|
unsigned long int D) |
|
Set Q to N/D, rounded towards -infinity. |
|
|
|
The function `mpz_fdiv_q_ui' returns the remainder. |
|
|
|
- Function: void mpz_fdiv_r (mpz_t R, mpz_t N, mpz_t D) |
|
- Function: unsigned long int mpz_fdiv_r_ui (mpz_t R, mpz_t N, |
|
unsigned long int D) |
|
Set R to (N - N/D * D), where the quotient is rounded towards |
|
-infinity. Unless R becomes zero, it will get the same sign as D. |
|
|
|
The function `mpz_fdiv_r_ui' returns the remainder. |
|
|
|
- Function: void mpz_fdiv_qr (mpz_t Q, mpz_t R, mpz_t N, mpz_t D) |
|
- Function: unsigned long int mpz_fdiv_qr_ui (mpz_t Q, mpz_t R, mpz_t |
|
N, unsigned long int D) |
|
Set Q to N/D, rounded towards -infinity. Set R to (N - N/D * D). |
|
Unless R becomes zero, it will get the same sign as D. If Q and R |
|
are the same variable, the results are undefined. |
|
|
|
The function `mpz_fdiv_qr_ui' returns the remainder. |
|
|
|
- Function: unsigned long int mpz_fdiv_ui (mpz_t N, unsigned long int |
|
D) |
|
Like `mpz_fdiv_r_ui', but the remainder is not stored anywhere; it |
|
is just returned. |
|
|
|
- Function: void mpz_cdiv_q (mpz_t Q, mpz_t N, mpz_t D) |
|
- Function: unsigned long int mpz_cdiv_q_ui (mpz_t Q, mpz_t N, |
|
unsigned long int D) |
|
Set Q to N/D, rounded towards +infinity. |
|
|
|
The function `mpz_cdiv_q_ui' returns the negated remainder. |
|
|
|
- Function: void mpz_cdiv_r (mpz_t R, mpz_t N, mpz_t D) |
|
- Function: unsigned long int mpz_cdiv_r_ui (mpz_t R, mpz_t N, |
|
unsigned long int D) |
|
Set R to (N - N/D * D), where the quotient is rounded towards |
|
+infinity. Unless R becomes zero, it will get the opposite sign |
|
as D. |
|
|
|
The function `mpz_cdiv_r_ui' returns the negated remainder. |
|
|
|
- Function: void mpz_cdiv_qr (mpz_t Q, mpz_t R, mpz_t N, mpz_t D) |
|
- Function: unsigned long int mpz_cdiv_qr_ui (mpz_t Q, mpz_t R, mpz_t |
|
N, unsigned long int D) |
|
Set Q to N/D, rounded towards +infinity. Set R to (N - N/D * D). |
|
Unless R becomes zero, it will get the opposite sign as D. If Q |
|
and R are the same variable, the results are undefined. |
|
|
|
The function `mpz_cdiv_qr_ui' returns the negated remainder. |
|
|
|
- Function: unsigned long int mpz_cdiv_ui (mpz_t N, unsigned long int |
|
D) |
|
Like `mpz_tdiv_r_ui', but the remainder is not stored anywhere; its |
|
negated value is just returned. |
|
|
|
- Function: void mpz_mod (mpz_t R, mpz_t N, mpz_t D) |
|
- Function: unsigned long int mpz_mod_ui (mpz_t R, mpz_t N, unsigned |
|
long int D) |
|
Set R to N `mod' D. The sign of the divisor is ignored; the |
|
result is always non-negative. |
|
|
|
The function `mpz_mod_ui' returns the remainder. |
|
|
|
- Function: void mpz_divexact (mpz_t Q, mpz_t N, mpz_t D) |
|
Set Q to N/D. This function produces correct results only when it |
|
is known in advance that D divides N. |
|
|
|
Since mpz_divexact is much faster than any of the other routines |
|
that produce the quotient (*note References:: Jebelean), it is the |
|
best choice for instances in which exact division is known to |
|
occur, such as reducing a rational to lowest terms. |
|
|
|
- Function: void mpz_tdiv_q_2exp (mpz_t Q, mpz_t N, unsigned long int |
|
D) |
|
Set Q to N divided by 2 raised to D. The quotient is truncated |
|
towards 0. |
|
|
|
- Function: void mpz_tdiv_r_2exp (mpz_t R, mpz_t N, unsigned long int |
|
D) |
|
Divide N by (2 raised to D), rounding the quotient towards 0, and |
|
put the remainder in R. Unless it is zero, R will have the same |
|
sign as N. |
|
|
|
- Function: void mpz_fdiv_q_2exp (mpz_t Q, mpz_t N, unsigned long int |
|
D) |
|
Set Q to N divided by 2 raised to D, rounded towards -infinity. |
|
This operation can also be defined as arithmetic right shift D bit |
|
positions. |
|
|
|
- Function: void mpz_fdiv_r_2exp (mpz_t R, mpz_t N, unsigned long int |
|
D) |
|
Divide N by (2 raised to D), rounding the quotient towards |
|
-infinity, and put the remainder in R. The sign of R will always |
|
be positive. This operation can also be defined as masking of the |
|
D least significant bits. |
|
|
|
|
File: gmp.info, Node: Integer Exponentiation, Next: Integer Roots, Prev: Integer Division, Up: Integer Functions |
File: gmp.info, Node: Integer Exponentiation, Next: Integer Roots, Prev: Integer Division, Up: Integer Functions |
|
|
Exponentiation Functions |
Exponentiation Functions |
Line 577 Miscellaneous Functions |
|
Line 740 Miscellaneous Functions |
|
- Function: double mpq_get_d (mpq_t OP) |
- Function: double mpq_get_d (mpq_t OP) |
Convert OP to a double. |
Convert OP to a double. |
|
|
- Function: double mpq_set_d (mpq_t ROP, double D) |
- Function: void mpq_set_d (mpq_t ROP, double D) |
Set ROP to the value of d, without rounding. |
Set ROP to the value of d, without rounding. |
|
|
These functions assign between either the numerator or denominator |
These functions assign between either the numerator or denominator |