<?php
$a = 1.234;
$b = 1.2e3;
$c = 7E-10;
?>
The regular expressions are as follows:
Floating point numbers: [0-9]+
Double type: ([0-9][.] {Lnum}) | ({lnum}[.] [0-9]*)
Exponential expression: [+-]? (({lnum} | {Dnum}) [EE] [+-]? {Lnum})
=========================
Maximum floating-point number PHP code is as follows:
<?php
function Float_max ($mul = 2, $affine = 1) {
$max = 1; $omax = 0;
while ((string) $max!= ' INF ') {$omax = $max; $max *= $mul;}
for ($i = 0; $i < $affine; $i + +) {
$pmax = 1; $max = $omax;
while ((string) $max!= ' INF ') {
$omax = $max;
$max + + $pmax;
$pmax *= $mul;
}
}
return $omax;
}
echo "Maximum floating-point number:"; Var_dump (Float_max ());
?>
=========================
The results are as follows (platform-related):
Maximum floating-point number: float (1.79769313486E+308)
Considerations about floating-point precision:
A simple decimal fraction can lose precision as 0.1 or 0.7 in a format converted to an internal binary:
For example, floor (0.1+0.7) *10 usually returns 7 rather than the expected 8, because the internal representation of the result is actually 7.9.
It is impossible to accurately express certain decimal points with a finite number of digits.
For example, the decimal 1/3 becomes 0.3.
So
1. Never believe that floating-point numbers are accurate to the last one,
2. And never compare two floating-point numbers for equality.
3. If you do need higher precision, you should use arbitrary precision mathematical functions or GMP functions.
Since PHP 5, if you try to convert an object to a floating-point number, a e_notice error is emitted.