Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there something that's larger than any numbers in PHP?

I need to simulate a ∞ in PHP.

So that min(∞,$number) is always $number.

like image 456
user198729 Avatar asked Dec 14 '09 11:12

user198729


1 Answers

I suppose that, for integers, you could use PHP_INT_MAX , the following code :

var_dump(PHP_INT_MAX);

Gives this output, on my machine :

int 2147483647


But you have to be careful ; see Integer overflow (quoting) :

If PHP encounters a number beyond the bounds of the integer type, it will be interpreted as a float instead. Also, an operation which results in a number beyond the bounds of the integer type will return a float instead.

And, from the Floating point numbers documentation page :

The size of a float is platform-dependent, although a maximum of ~1.8e308 with a precision of roughly 14 decimal digits is a common value (the 64 bit IEEE format).

Considering the integer overflow, and depending on your case, using this kind of value might be a better (?) solution...

like image 115
Pascal MARTIN Avatar answered Oct 20 '22 01:10

Pascal MARTIN