Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
is_finite() function in PHP
The is_finite() function checks if a value is finite or not. It returns true if the number is a finite number, else it returns false.
Syntax
is_finite(num)
Parameters
num − The number to be checked.
Return Value
The is_finite() function returns true if num is a finite number, else it returns false.
Example 1: Finite Number
Let's check if a regular number is finite ?
<?php
echo is_finite(1) ? 'true' : 'false';
?>
true
Example 2: Infinite Value
Let's check if log(0) (which is negative infinity) is finite ?
<?php
echo is_finite(log(0)) ? 'true' : 'false';
?>
false
Example 3: Various Test Cases
Here are several examples showing different scenarios ?
<?php
var_dump(is_finite(100)); // Normal number
var_dump(is_finite(INF)); // Positive infinity
var_dump(is_finite(-INF)); // Negative infinity
var_dump(is_finite(NAN)); // Not a Number
var_dump(is_finite(sqrt(-1))); // Square root of negative number
?>
bool(true) bool(false) bool(false) bool(false) bool(false)
Conclusion
The is_finite() function is useful for validating numeric values and ensuring they are within normal range. It returns false for infinity, negative infinity, and NaN values.
Advertisements
