I need to simulate a ∞ in PHP.
So that min(∞,$number)
is always $number
.
PHP actually has a predefined constant for "infinity": INF
. This isn't true infinity, but is essentially the largest float value possible. On 64-bit systems, the largest float is roughly equal to 1.8e308
, so this is considered to be equal to infinity.
$inf = INF;
var_dump(min($inf,PHP_INT_MAX)); // outputs int(9223372036854775807)
var_dump(min($inf,1.79e308)); // outputs float(1.79E+308)
var_dump(min($inf,1.799e308)); // outputs float(INF)
var_dump(min($inf,1.8e308)); // outputs float(INF)
var_dump($inf === 1.8e308); // outputs bool(true)
Note, any number with a value larger than the maximum float value will be cast to INF
. So therefore if we do, var_dump($inf === 1e50000);
, this will also output true
even though the maximum float is less than this.