Movatterモバイル変換


[0]ホーム

URL:


PHP 8.5.0 Alpha 2 available for testing
    is_infinite »
    « intdiv

    is_finite

    (PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

    is_finiteChecks whether a float is finite

    Description

    is_finite(float$num):bool

    Returns whether the givennum is a finite float.

    A finite float is neitherNAN (is_nan()), nor infinite (is_infinite()).

    Parameters

    num

    Thefloat to check

    Return Values

    true ifnum is none ofNAN,INF, -INF, elsefalse.

    Examples

    Example #1is_finite() example

    <?php
    $float
    =1.2345;
    var_dump($float,is_finite($float));

    $nan=sqrt(-1);
    var_dump($nan,is_finite($nan));

    $inf=1e308*2;
    var_dump($inf,is_finite($inf));
    ?>

    The above example will output:

    float(1.2345)bool(true)float(NAN)bool(false)float(INF)bool(false)

    See Also

    Found A Problem?

    Learn How To Improve This PageSubmit a Pull RequestReport a Bug
    add a note

    User Contributed Notes1 note

    Daniel Klein
    8 years ago
    (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
    ?>
    add a note
    To Top
    and to navigate •Enter to select •Esc to close
    PressEnter without selection to search using Google

    [8]ページ先頭

    ©2009-2025 Movatter.jp