Documentation Source Text

Check-in [e26caafc33]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix typos in the new floating point document.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e26caafc33fc03ff8ce62bdded49638530a380defa17c798b1f7c418a8feae32
User & Date: drh 2020-07-26 13:24:41
Context
2020-07-26
13:35
Improved wording of the floatingpoint.html document. (check-in: 010e930cc2 user: drh tags: trunk)
13:24
Fix typos in the new floating point document. (check-in: e26caafc33 user: drh tags: trunk)
2020-07-23
09:32
Add documentation for partial integrity_check. (check-in: 95ab7854dd user: drh tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to pages/floatingpoint.in.

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
..
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
...
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<p>
So-called "REAL" or floating point values are stored in the
<a href="https://en.wikipedia.org/wiki/IEEE_754">IEEE 754</a>
<a href="https://en.wikipedia.org/wiki/Double-precision_floating-point_format">Binary-64</a>
format.
This gives a range of positive values between approximately
1.7976931348623157e+308 and 4.9406564584124654e-324 with an equivalent
range of negative values.  A binary64 can also be 0.0 (and -0.0), postive
and negative infinity and "NaN" or "Not-a-Number".  Floating point
values approximate.

<p>
Pay close attention to the last sentence in the previous paragraph:
<blockquote><b>
Floating point values are approximate &larr; <u>Always</u> remember this!
</b></blockquote>

<p>
If you need an exact answer, you should not use binary64 floating-point
values, in SQLite or in any other product.  This is not an SQLite limitation.
It is a mathematical limitation inherient in the design of floating-point numbers.

<h2>Floating-Point Accuracy</h2>

<p>
SQLite promises to preserve the 15 most significant digits of a floating
point value.  However, it makes no guarantees about the accuracy of
computations on floating point values, as no such guarantees are possible.
................................................................................

<p>Not ever decimal number with fewer than 16 significant digits can be
represented exactly as a binary64 number.  In fact, most decimal numbers
with digits to the right of the decimal point lack an exact binary64
equivalent.  For example, if you have a database column that is intended
to hold an item price in dollars and cents, the only cents value that
can be exactly represented are 0.00, 0.25, 0.50, and 0.75.  Any other
numbers to the right of the decimal point result in an approximatation.
If you provide a "price" value of 47.49, that number will be represented
in binary64 as:

<blockquote>
6683623321994527 &times; 2<sup><small>-47</small></sup>
</blockquote>

................................................................................
<ul>
<li> decimal_add(A,B)
<li> decimal_sub(A,B)
<li> decimal_mul(A,B)
</ul>
</p>

<p>These functions respectively add, substract, and multiply their arguments
and return a new text string that is the decimal representation of the result.
There is no division operator at this time.

<p>Use the decimal_cmp(A,B) to compare two decimal values.  The result will
be negative, zero, or positive if A is less than, equal to, or greater than B,
respectively.








|

|










|







 







|







 







|







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
..
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
...
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<p>
So-called "REAL" or floating point values are stored in the
<a href="https://en.wikipedia.org/wiki/IEEE_754">IEEE 754</a>
<a href="https://en.wikipedia.org/wiki/Double-precision_floating-point_format">Binary-64</a>
format.
This gives a range of positive values between approximately
1.7976931348623157e+308 and 4.9406564584124654e-324 with an equivalent
range of negative values.  A binary64 can also be 0.0 (and -0.0), positive
and negative infinity and "NaN" or "Not-a-Number".  Floating point
values are approximate.

<p>
Pay close attention to the last sentence in the previous paragraph:
<blockquote><b>
Floating point values are approximate &larr; <u>Always</u> remember this!
</b></blockquote>

<p>
If you need an exact answer, you should not use binary64 floating-point
values, in SQLite or in any other product.  This is not an SQLite limitation.
It is a mathematical limitation inherent in the design of floating-point numbers.

<h2>Floating-Point Accuracy</h2>

<p>
SQLite promises to preserve the 15 most significant digits of a floating
point value.  However, it makes no guarantees about the accuracy of
computations on floating point values, as no such guarantees are possible.
................................................................................

<p>Not ever decimal number with fewer than 16 significant digits can be
represented exactly as a binary64 number.  In fact, most decimal numbers
with digits to the right of the decimal point lack an exact binary64
equivalent.  For example, if you have a database column that is intended
to hold an item price in dollars and cents, the only cents value that
can be exactly represented are 0.00, 0.25, 0.50, and 0.75.  Any other
numbers to the right of the decimal point result in an approximation.
If you provide a "price" value of 47.49, that number will be represented
in binary64 as:

<blockquote>
6683623321994527 &times; 2<sup><small>-47</small></sup>
</blockquote>

................................................................................
<ul>
<li> decimal_add(A,B)
<li> decimal_sub(A,B)
<li> decimal_mul(A,B)
</ul>
</p>

<p>These functions respectively add, subtract, and multiply their arguments
and return a new text string that is the decimal representation of the result.
There is no division operator at this time.

<p>Use the decimal_cmp(A,B) to compare two decimal values.  The result will
be negative, zero, or positive if A is less than, equal to, or greater than B,
respectively.