©
이 문서에서는 PHP 중국어 웹사이트 매뉴얼 풀어 주다
(PHP 4 >= 4.2.0, PHP 5)
is_infinite — 判断是否为无限值
$val
)
如果 val
为无穷大(正的或负的),例如 log(0)
的结果或者任何超出本平台的浮点数范围的值,则返回 TRUE
。
val
要检查的值
如果 val
为无穷大返回 TRUE
,否则返回 FALSE
。
[#1] espertalhao04 at hotmail dot com [2013-10-29 15:53:57]
fastest version to php <4.2:
<?php function is_infinite($v){$v=$v>>0;return -9e1000==$v||$v==9e1000;}; ?>
the $v=$v>>0; is just to ensure it is a number and its not mandatory.
effectively, the function can be reduced to:
<?php function is_infinite($v){return -9e1000==$v||$v==9e1000;}; ?>
this works because any number that is too big or too small for a float is considered to be infinite or -infinite.
[#2] Anonymous [2012-05-02 16:55:39]
PHP_INT_MAX is The largest integer supported in this build of PHP. Usually int(2147483647). Available since PHP 4.4.0 and PHP 5.0.5
[#3] stangelanda at arrowquick dot com [2007-08-28 07:29:05]
Actually any string ending in INF is more appropriate than any string beginning with INF. Since negative infinity evaluates to "-INF" but it is still infinite. However in either case the STRING "INF" is not infinite, only a float that converts to "INF" or "-INF" is infinite.
A more appropriate function might be:
<?php
if (!is_defined('is_infinite')) { function is_infinite($val) {
return (is_float($val) and ("$val"=='INF' or "$val"=='-INF'));
} }
?>
* However the above function is untested.
[#4] [2006-08-21 08:54:29]
@ david,
That will return true for any string ending with "INF".
I think substr("$value",0,3) would be more appropriate.
[#5] david(@t)nirvanis(d@t)org [2004-08-31 02:49:30]
If you have PHP lower than 4.2 you can simulate the behaviour:
function is_infinite($value) {
return (substr("$value",-3) == "INF");
}
(tested on php 4.1.2)