A number that can be counted is called a finite number. The isFinite()
function is used to check if the number is finite.
The figure below shows the visual representation of the isFinite()
function:
Note: Import
std.math
in your code to use theisFinite()
function. We can import it:import std.math
bool isFinite(number)
This function requires the number as a parameter.
This function returns true
if the value is finite
. Otherwise, it returns false
.
Note:
NaN
is not considered to be finite.
The following example shows how to use isFinite()
in D:
import core.stdc.stdio;import std.stdio;//header required for functionimport std.math;int main(){//integerwriteln ("The value of isFinite(4.0) : ",isFinite(4.0));//positive double valuewriteln ("The value of isFinite(2.56) : ",isFinite(2.56));//negative double valuewriteln ("The value of isFinite(-2.56) : ",isFinite(-2.56));//zerowriteln ("The value of isFinite(0.0) : ",isFinite(0.0));//infinitywriteln ("The value of isFinite(real.infinity) : ",isFinite(real.infinity));writeln ("The value of isFinite(-real.infinity) : ",isFinite(-real.infinity));//nanwriteln ("The value of isFinite(real.nan) : ",isFinite(real.nan));writeln ("The value of isFinite(-real.nan) : ",isFinite(-real.nan));return 0;}
Here is a line-by-line explanation of the code above:
std.math
library which is required to use isFinite()
function.4
is finite or not using the isFinite()
function.2.56
is finite or not using the isFinite()
function.-2.56
is finite or not using the isFinite()
function.zero
is finite or not using the isFinite()
function.isFinite()
function.NaN
and negative NaN
are finite or not using the isFinite()
function.