manpagez: man pages & more
info mpfr
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.9 Integer Related Functions

Function: int mpfr_rint (mpfr_t rop, mpfr_t op, mp_rnd_t rnd)
Function: int mpfr_ceil (mpfr_t rop, mpfr_t op)
Function: int mpfr_floor (mpfr_t rop, mpfr_t op)
Function: int mpfr_round (mpfr_t rop, mpfr_t op)
Function: int mpfr_trunc (mpfr_t rop, mpfr_t op)

Set rop to op rounded to an integer. mpfr_rint rounds to the nearest representable integer in the given rounding mode, mpfr_ceil rounds to the next higher or equal representable integer, mpfr_floor to the next lower or equal representable integer, mpfr_round to the nearest representable integer, rounding halfway cases away from zero, and mpfr_trunc to the next representable integer toward zero.

The returned value is zero when the result is exact, positive when it is greater than the original value of op, and negative when it is smaller. More precisely, the returned value is 0 when op is an integer representable in rop, 1 or -1 when op is an integer that is not representable in rop, 2 or -2 when op is not an integer.

Note that mpfr_round is different from mpfr_rint called with the rounding to nearest mode (where halfway cases are rounded to an even integer or significand). Note also that no double rounding is performed; for instance, 4.5 (100.1 in binary) is rounded by mpfr_round to 4 (100 in binary) in 2-bit precision, though round(4.5) is equal to 5 and 5 (101 in binary) is rounded to 6 (110 in binary) in 2-bit precision.

Function: int mpfr_rint_ceil (mpfr_t rop, mpfr_t op, mp_rnd_t rnd)
Function: int mpfr_rint_floor (mpfr_t rop, mpfr_t op, mp_rnd_t rnd)
Function: int mpfr_rint_round (mpfr_t rop, mpfr_t op, mp_rnd_t rnd)
Function: int mpfr_rint_trunc (mpfr_t rop, mpfr_t op, mp_rnd_t rnd)

Set rop to op rounded to an integer. mpfr_rint_ceil rounds to the next higher or equal integer, mpfr_rint_floor to the next lower or equal integer, mpfr_rint_round to the nearest integer, rounding halfway cases away from zero, and mpfr_rint_trunc to the next integer toward zero. If the result is not representable, it is rounded in the direction rnd. The returned value is the ternary value associated with the considered round-to-integer function (regarded in the same way as any other mathematical function).

Function: int mpfr_frac (mpfr_t rop, mpfr_t op, mp_rnd_t rnd)

Set rop to the fractional part of op, having the same sign as op, rounded in the direction rnd (unlike in mpfr_rint, rnd affects only how the exact fractional part is rounded, not how the fractional part is generated).

Function: int mpfr_remainder (mpfr_t r, mpfr_t x, mpfr_t y, mp_rnd_t rnd)
Function: int mpfr_remquo (mpfr_t r, long* q, mpfr_t x, mpfr_t y, mp_rnd_t rnd)

Set r to the remainder of the division of x by y, with quotient rounded to the nearest integer (ties rounded to even), and r rounded according to the direction rnd. If r is zero, it has the sign of x. The return value is the ternary value corresponding to r. Additionally, mpfr_remquo stores the low significant bits from the quotient in *q (more precisely the number of bits in a long minus one), with the sign of x divided by y (except if those low bits are all zero, in which case zero is returned). Note that x may be so large in magnitude relative to y that an exact representation of the quotient is not practical. These functions are useful for additive argument reduction.

Function: int mpfr_integer_p (mpfr_t op)

Return non-zero iff op is an integer.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© manpagez.com 2000-2025
Individual documents may contain additional copyright information.