Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there something similar to NEGATIVE_INFINITY in php?

Tags:

php

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?

like image 410
Yann Chabot Avatar asked Jan 13 '16 15:01

Yann Chabot


People also ask

Are you familiar with the concept of negative infinity in JavaScript?

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.

What is number NEGATIVE_INFINITY?

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 .

How do you get negative infinity in JavaScript?

JavaScript Number NEGATIVE_INFINITY NEGATIVE_INFINITY returns negative infinity.

Is there 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.


1 Answers

-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
like image 66
Y.Hermes Avatar answered Oct 24 '22 05:10

Y.Hermes