language/types/float.xml
a1e3d629b4f01ee41bd38391cd5c6ae5ee894cb3
...
...
@@ -15,28 +15,29 @@
15
15
$a = 1.234;
16
16
$b = 1.2e3;
17
17
$c = 7E-10;
18
+
$d = 1_234.567; // as of PHP 7.4.0
18
19
?>
19
20
]]>
20
21
</programlisting>
21
22
</informalexample>
22
23

23
24
<para>
24
-
Formally:
25
+
Formally as of PHP 7.4.0 (previously, underscores have not been allowed):
25
26
</para>
26
27

27
28
<informalexample>
28
29
<programlisting>
29
30
<![CDATA[
30
-
LNUM [0-9]+
31
-
DNUM ([0-9]*[\.]{LNUM}) | ({LNUM}[\.][0-9]*)
32
-
EXPONENT_DNUM [+-]?(({LNUM} | {DNUM}) [eE][+-]? {LNUM})
31
+
LNUM [0-9]+(_[0-9]+)*
32
+
DNUM ({LNUM}?"."{LNUM}) | ({LNUM}"."{LNUM}?)
33
+
EXPONENT_DNUM (({LNUM} | {DNUM}) [eE][+-]? {LNUM})
33
34
]]>
34
35
</programlisting>
35
36
</informalexample>
36
37

37
38
<para>
38
-
The size of a float is platform-dependent, although a maximum of ~1.8e308 with
39
-
a precision of roughly 14 decimal digits is a common value (the 64 bit IEEE
39
+
The size of a float is platform-dependent, although a maximum of approximately 1.8e308
40
+
with a precision of roughly 14 decimal digits is a common value (the 64 bit IEEE
40
41
format).
41
42
</para>
42
43

...
...
@@ -81,17 +82,36 @@ EXPONENT_DNUM [+-]?(({LNUM} | {DNUM}) [eE][+-]? {LNUM})
81
82
<sect2 xml:id="language.types.float.casting">
82
83
<title>Converting to float</title>
83
84

84
-
<para>
85
-
For information on converting <type>string</type>s to <type>float</type>, see
86
-
<link linkend="language.types.string.conversion">String conversion to
87
-
numbers</link>. For values of other types, the conversion is performed by
88
-
converting the value to <type>integer</type> first and then to
89
-
<type>float</type>. See
90
-
<link linkend="language.types.integer.casting">Converting to integer</link>
91
-
for more information. As of PHP 5, a notice is thrown if an
92
-
<type>object</type> is converted to <type>float</type>.
93
-
</para>
85
+
<sect3 xml:id="language.types.float.casting.from-string">
86
+
<title>From strings</title>
94
87

88
+
<simpara>
89
+
If the string is
90
+
<link linkend="language.types.numeric-strings">numeric</link>
91
+
or leading numeric then it will resolve to the
92
+
corresponding float value, otherwise it is converted to zero
93
+
(<literal>0</literal>).
94
+
</simpara>
95
+
</sect3>
96
+

97
+
<sect3 xml:id="language.types.float.casting.from-other">
98
+
<title>From other types</title>
99
+

100
+
<para>
101
+
For values of other types, the conversion is performed by converting the
102
+
value to <type>int</type> first and then to <type>float</type>. See
103
+
<link linkend="language.types.integer.casting">Converting to integer</link>
104
+
for more information.
105
+
</para>
106
+

107
+
<note>
108
+
<para>
109
+
As certain types have undefined behavior when converting to
110
+
<type>int</type>, this is also the case when converting to
111
+
<type>float</type>.
112
+
</para>
113
+
</note>
114
+
</sect3>
95
115
</sect2>
96
116

97
117
<sect2 xml:id="language.types.float.comparison">
...
...
@@ -137,7 +157,7 @@ if(abs($a-$b) < $epsilon) {
137
157
Some numeric operations can result in a value represented by the constant
138
158
<constant>NAN</constant>. This result represents an undefined or
139
159
unrepresentable value in floating-point calculations. Any loose or strict
140
-
comparisons of this value against any other value, including itself, will
160
+
comparisons of this value against any other value, including itself, but except &true;, will
141
161
have a result of &false;.
142
162
</para>
143
163
<para>
144
164