File: next_float.html

package info (click to toggle)
scipy 1.16.0-1exp7
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 234,820 kB
  • sloc: cpp: 503,145; python: 344,611; ansic: 195,638; javascript: 89,566; fortran: 56,210; cs: 3,081; f90: 1,150; sh: 848; makefile: 785; pascal: 284; csh: 135; lisp: 134; xml: 56; perl: 51
file content (115 lines) | stat: -rw-r--r-- 8,419 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Floating-Point Representation Distance (ULP), and Finding Adjacent Floating-Point Values</title>
<link rel="stylesheet" href="../math.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Math Toolkit 4.2.1">
<link rel="up" href="../utils.html" title="Chapter 2. Floating Point Utilities">
<link rel="prev" href="fp_facets/rationale.html" title="Design Rationale">
<link rel="next" href="next_float/nextafter.html" title="Finding the Next Representable Value in a Specific Direction (nextafter)">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="fp_facets/rationale.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../utils.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="next_float/nextafter.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="math_toolkit.next_float"></a><a class="link" href="next_float.html" title="Floating-Point Representation Distance (ULP), and Finding Adjacent Floating-Point Values">Floating-Point Representation
    Distance (ULP), and Finding Adjacent Floating-Point Values</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="next_float/nextafter.html">Finding the Next Representable
      Value in a Specific Direction (nextafter)</a></span></dt>
<dt><span class="section"><a href="next_float/float_next.html">Finding the Next
      Greater Representable Value (float_next)</a></span></dt>
<dt><span class="section"><a href="next_float/float_prior.html">Finding the Next
      Smaller Representable Value (float_prior)</a></span></dt>
<dt><span class="section"><a href="next_float/float_distance.html">Calculating the
      Representation Distance Between Two floating-point Values (ULP) float_distance</a></span></dt>
<dt><span class="section"><a href="next_float/float_advance.html">Advancing a floating-point
      Value by a Specific Representation Distance (ULP) float_advance</a></span></dt>
<dt><span class="section"><a href="next_float/ulp.html">Obtaining the Size of a
      Unit In the Last Place - ULP</a></span></dt>
</dl></div>
<p>
      <a href="http://en.wikipedia.org/wiki/Unit_in_the_last_place" target="_top">Unit of Least
      Precision or Unit in the Last Place</a> is the gap between two different,
      but as close as possible, floating-point numbers.
    </p>
<p>
      Most decimal values, for example 0.1, cannot be exactly represented as floating-point
      values, but will be stored as the <a href="http://en.wikipedia.org/wiki/Floating_point#Representable_numbers.2C_conversion_and_rounding" target="_top">closest
      representable floating-point</a>.
    </p>
<p>
      Functions are provided for finding adjacent greater and lesser floating-point
      values, and estimating the number of gaps between any two floating-point values.
    </p>
<p>
      The floating-point type (FPT) must have has a fixed number of bits in the representation.
      The number of bits may set at runtime, but must be the same for all numbers.
      For example, <a href="http://shoup.net/ntl/doc/quad_float.txt" target="_top">NTL::quad_float</a>
      type (fixed 128-bit representation), <a href="http://shoup.net/ntl/doc/RR.txt" target="_top">NTL::RR</a>
      type (arbitrary but fixed decimal digits, default 150) or <a href="../../../../../libs/multiprecision/doc/html/index.html" target="_top">Boost.Multiprecision</a>
      <a href="../../../../../libs/multiprecision/doc/html/boost_multiprecision/tut/floats/cpp_dec_float.html" target="_top">cpp_dec_float</a>
      and<a href="../../../../../libs/multiprecision/doc/html/boost_multiprecision/tut/floats/cpp_bin_float.html" target="_top">cpp_bin_float</a>
      are fixed at runtime, but <span class="bold"><strong>not</strong></span> a type that
      extends the representation to provide an exact representation for any number,
      for example <a href="http://keithbriggs.info/xrc.html" target="_top">XRC eXact Real in
      C</a>.
    </p>
<p>
      The accuracy of mathematical functions can be assessed and displayed in terms
      of <a href="https://en.wikipedia.org/wiki/Unit_in_the_last_place" target="_top">Unit in
      the Last Place</a>, often as a ulps plot or by binning the differences
      as a histogram. Samples are evaluated using the implementation under test and
      compared with 'known good' representation obtained using a more accurate method.
      Other implementations, often using arbitrary precision arithmetic, for example
      <a href="http://www.wolframalpha.com/" target="_top">Wolfram Alpha</a> are one source
      of references values. The other method, used widely in Boost.Math special functions,
      it to carry out the same algorithm, but using a higher precision type, typically
      using Boost.Multiprecision types like <code class="computeroutput"><span class="identifier">cpp_bin_float_quad</span></code>
      for 128-bit (about 35 decimal digit precision), or <code class="computeroutput"><span class="identifier">cpp_bin_float_50</span></code>
      (for 50 decimal digit precision).
    </p>
<p>
      When converted to a particular machine representation, say <code class="computeroutput"><span class="keyword">double</span></code>,
      say using a <code class="computeroutput"><span class="keyword">static_cast</span></code>, the value
      is the nearest representation possible for the <code class="computeroutput"><span class="keyword">double</span></code>
      type. This value cannot be 'wrong' by more than half a <a href="http://en.wikipedia.org/wiki/Unit_in_the_last_place" target="_top">Unit
      in the last place (ULP)</a>, and can be obtained using the Boost.Math function
      <code class="computeroutput"><span class="identifier">ulp</span></code>. (Unless the algorithm
      is fundamentally flawed, something that should be revealed by 'sanity' checks
      using some independent sources).
    </p>
<p>
      See some discussion and example plots by Cleve Moler of Mathworks <a href="https://blogs.mathworks.com/cleve/2017/01/23/ulps-plots-reveal-math-function-accurary/" target="_top">ulps
      plots reveal math-function accuracy</a>.
    </p>
</div>
<div class="copyright-footer">Copyright © 2006-2021 Nikhar Agrawal, Anton Bikineev, Matthew Borland,
      Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert Holin, Bruno
      Lalande, John Maddock, Evan Miller, Jeremy Murphy, Matthew Pulver, Johan Råde,
      Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, Daryle
      Walker and Xiaogang Zhang<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="fp_facets/rationale.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../utils.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="next_float/nextafter.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>