Next: Floating-Point Values on Special Numbers, Previous: MPFR Variable Conventions, Up: MPFR Basics [Index]
The following five rounding modes are supported:
MPFR_RNDN
: round to nearest (roundTiesToEven in IEEE 754-2008),
MPFR_RNDZ
: round toward zero (roundTowardZero in IEEE 754-2008),
MPFR_RNDU
: round toward plus infinity (roundTowardPositive in IEEE 754-2008),
MPFR_RNDD
: round toward minus infinity (roundTowardNegative in IEEE 754-2008),
MPFR_RNDA
: round away from zero.
The ‘round to nearest’ mode works as in the IEEE 754 standard: in case the number to be rounded lies exactly in the middle of two representable numbers, it is rounded to the one with the least significant bit set to zero. For example, the number 2.5, which is represented by (10.1) in binary, is rounded to (10.0)=2 with a precision of two bits, and not to (11.0)=3. This rule avoids the drift phenomenon mentioned by Knuth in volume 2 of The Art of Computer Programming (Section 4.2.2).
Most MPFR functions take as first argument the destination variable, as
second and following arguments the input variables, as last argument a
rounding mode, and have a return value of type int
, called the
ternary value. The value stored in the destination variable is
correctly rounded, i.e., MPFR behaves as if it computed the result with
an infinite precision, then rounded it to the precision of this variable.
The input variables are regarded as exact (in particular, their precision
does not affect the result).
As a consequence, in case of a non-zero real rounded result, the error on the result is less or equal to 1/2 ulp (unit in the last place) of that result in the rounding to nearest mode, and less than 1 ulp of that result in the directed rounding modes (a ulp is the weight of the least significant represented bit of the result after rounding).
Unless documented otherwise, functions returning an int
return
a ternary value.
If the ternary value is zero, it means that the value stored in the
destination variable is the exact result of the corresponding mathematical
function. If the ternary value is positive (resp. negative), it means
the value stored in the destination variable is greater (resp. lower)
than the exact result. For example with the MPFR_RNDU
rounding mode,
the ternary value is usually positive, except when the result is exact, in
which case it is zero. In the case of an infinite result, it is considered
as inexact when it was obtained by overflow, and exact otherwise. A NaN
result (Not-a-Number) always corresponds to an exact return value.
The opposite of a returned ternary value is guaranteed to be representable
in an int
.
Unless documented otherwise, functions returning as result the value 1
(or any other value specified in this manual)
for special cases (like acos(0)
) yield an overflow or
an underflow if that value is not representable in the current exponent range.
Next: Floating-Point Values on Special Numbers, Previous: MPFR Variable Conventions, Up: MPFR Basics [Index]