I love the negative infinity value in javascript, I think it's useful and clean in many case to use it but couldn't find something similar in PHP, does it exists?
The negative infinity in JavaScript is a constant value which is used to represent a value which is the lowest available. This means that no other number is lesser than this value. It can be generated using a self-made function or by an arithmetic operation.
Description. The value of Number. NEGATIVE_INFINITY is the same as the negative value of the global object's Infinity property. This value behaves slightly differently than mathematical infinity: Any positive value, including POSITIVE_INFINITY , multiplied by NEGATIVE_INFINITY is NEGATIVE_INFINITY .
JavaScript Number NEGATIVE_INFINITY NEGATIVE_INFINITY returns negative infinity.
Infinity added to the biggest negative number you can think of (or minus the biggest conceivable positive number) is still infinity. So, infinity includes all negative numbers. Even infinity minus infinity is still infinity, if we're talking about infinity here, right? Except that quite often infinity is a number.
-INF
Got it from comment at PHP Documentation:
I just learnt of INF today and found out that it can be used in comparisons:
echo 5000 < INF ? 'yes' : 'no'; // outputs 'yes' echo INF < INF ? 'yes' : 'no'; // outputs 'no' echo INF <= INF ? 'yes' : 'no'; // outputs 'yes' echo INF == INF ? 'yes' : 'no'; // outputs 'yes'
You can also take its negative:
echo -INF < -5000 ? 'yes' : 'no'; // outputs 'yes'
Division by INF is allowed:
echo 1/INF; // outputs '0'
And test for it:
is_infinite(INF); returns true is_infinite(-INF); returns true is_infinite(1.01); return false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With