is_finite
(PHP 4 >= 4.2.0, PHP 5)
is_finite — Finds whether a value is a legal finite number
Description
bool is_finite
( float
$val
)
Checks whether val
is a legal finite
on this platform.
Parameters
-
val
-
The value to check
Return Values
TRUE
if val
is a legal finite
number within the allowed range for a PHP float on this platform,
else FALSE
.
See Also
- is_infinite() - Finds whether a value is infinite
- is_nan() - Finds whether a value is not a number
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Математические расширения
- Математические функции
- abs
- acos
- acosh
- asin
- asinh
- atan2
- atan
- atanh
- base_convert
- bindec
- ceil
- cos
- cosh
- decbin
- dechex
- decoct
- deg2rad
- exp
- expm1
- floor
- fmod
- getrandmax
- hexdec
- hypot
- intdiv
- is_finite
- is_infinite
- is_nan
- lcg_value
- log10
- log1p
- log
- max
- min
- mt_getrandmax
- mt_rand
- mt_srand
- octdec
- pi
- pow
- rad2deg
- rand
- round
- sin
- sinh
- sqrt
- srand
- tan
- tanh
Коментарии
(is_finite($float)) is equivalent to (!is_infinite($float) && !is_nan($float)), i.e. a number can only be one of finite, infinite and NaN. You don't need to check both is_infinite() and is_nan() to see if a number is invalid or out of range.
<?php
$finite = 42;
$infinite = log(0);
$nan = acos(2);
var_dump(is_finite($finite), is_infinite($finite), is_nan($finite)); // true, false, false
var_dump(is_finite($infinite), is_infinite($infinite), is_nan($infinite)); // false, true, false
var_dump(is_finite($nan), is_infinite($nan), is_nan($nan)); // false, false, true
?>