You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
6.9 KiB
HTML
132 lines
6.9 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<!-- This manual documents how to install and use the Multiple Precision
|
|
Floating-Point Reliable Library, version 3.1.4.
|
|
|
|
Copyright 1991, 1993-2016 Free Software Foundation, Inc.
|
|
|
|
Permission is granted to copy, distribute and/or modify this document under
|
|
the terms of the GNU Free Documentation License, Version 1.2 or any later
|
|
version published by the Free Software Foundation; with no Invariant Sections,
|
|
with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the
|
|
license is included in GNU Free Documentation License. -->
|
|
<!-- Created by GNU Texinfo 6.4, http://www.gnu.org/software/texinfo/ -->
|
|
<head>
|
|
<title>Rounding Modes (GNU MPFR 3.1.4)</title>
|
|
|
|
<meta name="description" content="How to install and use GNU MPFR, a library for reliable multiple precision
|
|
floating-point arithmetic, version 3.1.4.">
|
|
<meta name="keywords" content="Rounding Modes (GNU MPFR 3.1.4)">
|
|
<meta name="resource-type" content="document">
|
|
<meta name="distribution" content="global">
|
|
<meta name="Generator" content="makeinfo">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<link href="index.html#Top" rel="start" title="Top">
|
|
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
|
|
<link href="MPFR-Basics.html#MPFR-Basics" rel="up" title="MPFR Basics">
|
|
<link href="Floating_002dPoint-Values-on-Special-Numbers.html#Floating_002dPoint-Values-on-Special-Numbers" rel="next" title="Floating-Point Values on Special Numbers">
|
|
<link href="MPFR-Variable-Conventions.html#MPFR-Variable-Conventions" rel="prev" title="MPFR Variable Conventions">
|
|
<style type="text/css">
|
|
<!--
|
|
a.summary-letter {text-decoration: none}
|
|
blockquote.indentedblock {margin-right: 0em}
|
|
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
|
|
blockquote.smallquotation {font-size: smaller}
|
|
div.display {margin-left: 3.2em}
|
|
div.example {margin-left: 3.2em}
|
|
div.lisp {margin-left: 3.2em}
|
|
div.smalldisplay {margin-left: 3.2em}
|
|
div.smallexample {margin-left: 3.2em}
|
|
div.smalllisp {margin-left: 3.2em}
|
|
kbd {font-style: oblique}
|
|
pre.display {font-family: inherit}
|
|
pre.format {font-family: inherit}
|
|
pre.menu-comment {font-family: serif}
|
|
pre.menu-preformatted {font-family: serif}
|
|
pre.smalldisplay {font-family: inherit; font-size: smaller}
|
|
pre.smallexample {font-size: smaller}
|
|
pre.smallformat {font-family: inherit; font-size: smaller}
|
|
pre.smalllisp {font-size: smaller}
|
|
span.nolinebreak {white-space: nowrap}
|
|
span.roman {font-family: initial; font-weight: normal}
|
|
span.sansserif {font-family: sans-serif; font-weight: normal}
|
|
ul.no-bullet {list-style: none}
|
|
-->
|
|
</style>
|
|
|
|
|
|
</head>
|
|
|
|
<body lang="en">
|
|
<a name="Rounding-Modes"></a>
|
|
<div class="header">
|
|
<p>
|
|
Next: <a href="Floating_002dPoint-Values-on-Special-Numbers.html#Floating_002dPoint-Values-on-Special-Numbers" accesskey="n" rel="next">Floating-Point Values on Special Numbers</a>, Previous: <a href="MPFR-Variable-Conventions.html#MPFR-Variable-Conventions" accesskey="p" rel="prev">MPFR Variable Conventions</a>, Up: <a href="MPFR-Basics.html#MPFR-Basics" accesskey="u" rel="up">MPFR Basics</a> [<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
|
|
</div>
|
|
<hr>
|
|
<a name="Rounding-Modes-1"></a>
|
|
<h3 class="section">4.4 Rounding Modes</h3>
|
|
|
|
<p>The following five rounding modes are supported:
|
|
</p><ul>
|
|
<li> <code>MPFR_RNDN</code>: round to nearest (roundTiesToEven in IEEE 754-2008),
|
|
</li><li> <code>MPFR_RNDZ</code>: round toward zero (roundTowardZero in IEEE 754-2008),
|
|
</li><li> <code>MPFR_RNDU</code>: round toward plus infinity (roundTowardPositive in IEEE 754-2008),
|
|
</li><li> <code>MPFR_RNDD</code>: round toward minus infinity (roundTowardNegative in IEEE 754-2008),
|
|
</li><li> <code>MPFR_RNDA</code>: round away from zero.
|
|
</li></ul>
|
|
|
|
<p>The ‘<samp>round to nearest</samp>’ 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 <em>drift</em> phenomenon mentioned by Knuth in volume 2
|
|
of The Art of Computer Programming (Section 4.2.2).
|
|
</p>
|
|
<a name="ternary-value"></a><a name="index-Ternary-value"></a>
|
|
<p>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 <code>int</code>, called the
|
|
<em>ternary value</em>. 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).
|
|
</p>
|
|
<p>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).
|
|
</p>
|
|
<p>Unless documented otherwise, functions returning an <code>int</code> 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 <code>MPFR_RNDU</code> 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 <code>int</code>.
|
|
</p>
|
|
<p>Unless documented otherwise, functions returning as result the value <code>1</code>
|
|
(or any other value specified in this manual)
|
|
for special cases (like <code>acos(0)</code>) yield an overflow or
|
|
an underflow if that value is not representable in the current exponent range.
|
|
</p>
|
|
<hr>
|
|
<div class="header">
|
|
<p>
|
|
Next: <a href="Floating_002dPoint-Values-on-Special-Numbers.html#Floating_002dPoint-Values-on-Special-Numbers" accesskey="n" rel="next">Floating-Point Values on Special Numbers</a>, Previous: <a href="MPFR-Variable-Conventions.html#MPFR-Variable-Conventions" accesskey="p" rel="prev">MPFR Variable Conventions</a>, Up: <a href="MPFR-Basics.html#MPFR-Basics" accesskey="u" rel="up">MPFR Basics</a> [<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
|
|
</div>
|
|
|
|
|
|
|
|
</body>
|
|
</html>
|