$a = 1.234;
$b = 1.2e3;
$c = 7E-10;
?>
正则表达示如下:
浮点数: [0-9]+
双精度型: ([0-9][.]{LNUM}) | ({LNUM}[.][0-9]*)
指数表达式: [+-]?(({LNUM} | {DNUM}) [eE][+-]? {LNUM})
=========================
最大浮点数php代码如下:
function float_max($mul = 2, $affine = 1) {
$max = 1; $omax = 0;
while((string)$max != 'INF') { $omax = $max; $max *= $mul; }
for($i = 0; $i
$pmax = 1; $max = $omax;
while((string)$max != 'INF') {
$omax = $max;
$max += $pmax;
$pmax *= $mul;
}
}
return $omax;
}
echo "最大浮点数:" ;var_dump(float_max());
?>
=========================
结果如下(与平台相关):
最大浮点数:float(1.79769313486E+308)
关于浮点数精度的注意事项:
简单的十进制分数如同 0.1 或 0.7 在转换为内部二进制的格式会丢失精度:
例如,floor((0.1+0.7)*10) 通常会返回 7 而不是预期中的 8,因为该结果内部的表示其实是7.9。
就是不可能精确的用有限位数表达某些十进制分数。
例如,十进制的 1/3 变成了 0.3。
所以
1。永远不要相信浮点数结果精确到了最后一位,
2。也永远不要比较两个浮点数是否相等。
3。如果确实需要更高的精度,应该使用任意精度数学函数或者 gmp 函数。
自 PHP 5 起,如果试图将对象转换为浮点数,会发出一条 E_NOTICE 错误。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools

Dreamweaver CS6
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
