|
1 | 1 | <?xml version="1.0" encoding="utf-8"?> |
2 | 2 | <!-- $Revision$ --> |
3 | 3 | <sect1 xml:id="language.types.float" xmlns:xlink="http://www.w3.org/1999/xlink"> |
4 | | - <title>Floating point numbers</title> |
| 4 | + <title>Floating-point numbers</title> |
5 | 5 |
|
6 | | - <para> |
7 | | - Floating point numbers (also known as "floats", "doubles", or "real numbers") |
| 6 | + <simpara> |
| 7 | + Floating-point numbers (also known as "floats", "doubles", or "real numbers") |
8 | 8 | can be specified using any of the following syntaxes: |
9 | | - </para> |
| 9 | + </simpara> |
10 | 10 |
|
11 | 11 | <informalexample> |
12 | 12 | <programlisting role="php"> |
@@ -42,36 +42,36 @@ EXPONENT_DNUM (({LNUM} | {DNUM}) [eE][+-]? {LNUM}) |
42 | 42 | </para> |
43 | 43 |
|
44 | 44 | <warning xml:id="warn.float-precision"> |
45 | | - <title>Floating point precision</title> |
| 45 | + <title>Floating-point precision</title> |
46 | 46 |
|
47 | | - <para> |
48 | | - Floating point numbers have limited precision. Although it depends on the |
| 47 | + <simpara> |
| 48 | + Floating-point numbers have limited precision. Although it depends on the |
49 | 49 | system, PHP typically uses the IEEE 754 double precision format, which will |
50 | 50 | give a maximum relative error due to rounding in the order of 1.11e-16. |
51 | | - Non elementary arithmetic operations may give larger errors, and, of course, |
| 51 | + Non-elementary arithmetic operations may give larger errors, and, of course, |
52 | 52 | error propagation must be considered when several operations are |
53 | 53 | compounded. |
54 | | - </para> |
| 54 | + </simpara> |
55 | 55 |
|
56 | | - <para> |
57 | | - Additionally, rational numbers that are exactly representable as floating |
58 | | - point numbers in base 10, like <literal>0.1</literal> or |
59 | | - <literal>0.7</literal>, do not have an exact representation as floating |
60 | | - point numbers in base 2, which is used internally, no matter the size of |
| 56 | + <simpara> |
| 57 | + Additionally, rational numbers that are exactly representable as floating-point |
| 58 | + numbers in base 10, like <literal>0.1</literal> or |
| 59 | + <literal>0.7</literal>, do not have an exact representation as floating-point |
| 60 | + numbers in base 2, which is used internally, no matter the size of |
61 | 61 | the mantissa. Hence, they cannot be converted into their internal binary |
62 | 62 | counterparts without a small loss of precision. This can lead to confusing |
63 | 63 | results: for example, <literal>floor((0.1+0.7)*10)</literal> will usually |
64 | 64 | return <literal>7</literal> instead of the expected <literal>8</literal>, |
65 | 65 | since the internal representation will be something like |
66 | 66 | <literal>7.9999999999999991118...</literal>. |
67 | | - </para> |
| 67 | + </simpara> |
68 | 68 |
|
69 | | - <para> |
70 | | - So never trust floating number results to the last digit, and do not compare |
71 | | - floating point numbers directly for equality. If higher precision is |
| 69 | + <simpara> |
| 70 | + So never trust floating-point number results to the last digit, and do not compare |
| 71 | + floating-point numbers directly for equality. If higher precision is |
72 | 72 | necessary, the <link linkend="ref.bc">arbitrary precision math functions</link> |
73 | 73 | and <link linkend="ref.gmp">gmp</link> functions are available. |
74 | | - </para> |
| 74 | + </simpara> |
75 | 75 |
|
76 | 76 | <para> |
77 | 77 | For a "simple" explanation, see the <link xlink:href="&url.floating.point.guide;">floating point guide</link> |
@@ -117,18 +117,18 @@ EXPONENT_DNUM (({LNUM} | {DNUM}) [eE][+-]? {LNUM}) |
117 | 117 | <sect2 xml:id="language.types.float.comparison"> |
118 | 118 | <title>Comparing floats</title> |
119 | 119 |
|
120 | | - <para> |
121 | | - As noted in the warning above, testing floating point values for equality is |
| 120 | + <simpara> |
| 121 | + As noted in the warning above, testing floating-point values for equality is |
122 | 122 | problematic, due to the way that they are represented internally. However, |
123 | | - there are ways to make comparisons of floating point values that work around |
| 123 | + there are ways to make comparisons of floating-point values that work around |
124 | 124 | these limitations. |
125 | | - </para> |
| 125 | + </simpara> |
126 | 126 |
|
127 | | - <para> |
128 | | - To test floating point values for equality, an upper bound on the relative |
| 127 | + <simpara> |
| 128 | + To test floating-point values for equality, an upper bound on the relative |
129 | 129 | error due to rounding is used. This value is known as the machine epsilon, |
130 | 130 | or unit roundoff, and is the smallest acceptable difference in calculations. |
131 | | - </para> |
| 131 | + </simpara> |
132 | 132 |
|
133 | 133 | <para> |
134 | 134 | <varname>$a</varname> and <varname>$b</varname> are equal to 5 digits of |
|
0 commit comments