PHP 7.2.0 Release Candidate 2 Released


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

is_infiniteIndique si un nombre est infini


bool is_infinite ( float $val )

Retourne TRUE si val est infini (positif ou négatif), comme le résultat de log(0) ou une valeur qui est trop grande pour être représentée par un nombre à virgule flottante sur cette plate-forme.

Liste de paramètres


La valeur à vérifier

Valeurs de retour

TRUE si val est une valeur infinie, sinon, FALSE.

Voir aussi

  • is_finite() - Indique si un nombre est fini
  • is_nan() - Indique si une valeur n'est pas un nombre

add a note add a note

User Contributed Notes 5 notes

11 years ago
@ david,

That will return true for any string ending with "INF".
I think substr("$value",0,3) would be more appropriate.
13 years ago
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)
stangelanda at arrowquick dot com
10 years ago
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:
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.
espertalhao04 at hotmail dot com
3 years ago
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.
5 years ago
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
To Top