![]() |
VOOZH | about |
Given any numerical value, it can be classified into 3 different classes such as Finite Number, Infinite Number, and Not a Number or commonly known as NaN. While developing a project that is highly dependent on User Inputs there might be many cases where the user provides inappropriate inputs while a function expects a finite numerical input thus creating an unhandled situation or unexpected result.
Thus it is a secure option to check whether a given input value is finite or not.
is_finite() Function
Syntax:
bool is_finite ($value)
Parameters: The function takes a single parameter which is a float that is to be checked.
Return Type: This function returns TRUE if the given value is finite otherwise returns FALSE.
Examples:
Input : $value = M_PI_4; Output : TRUE Input : $value = log(0); Output : FALSE
is_infinite() Function
Syntax:
bool is_infinite ($value)
Parameters: The function takes a single parameter which is a float that is to be checked.
Return Type: This function returns TRUE if the given value is infinite otherwise returns FALSE.
Examples:
Input : $value = M_PI_4; Output : FALSE Input : $value = log(0); Output : TRUE
is_nan() Function
Syntax:
bool is_nan ($value)
Parameters: The function takes a single parameter which is a float that is to be checked.
Return Type: This function returns TRUE if the given value is not a number otherwise returns FALSE.
Examples:
Input : $value = M_PI_4; Output : FALSE // cos function can not be greater than 1 Input : $value = acos(1.1); Output : TRUE
Below program illustrates the working of is_finite(), is_infinite(), is_nan() functions in PHP:
Output:
bool(true) bool(false) bool(false) bool(false) bool(true) bool(false) bool(false) bool(false) bool(true)
Note: