Dart double isInfinite
Syntax & Examples
double.isInfinite property
The `isInfinite` property in Dart checks whether a number is positive infinity or negative infinity.
Syntax of double.isInfinite
The syntax of double.isInfinite property is:
bool isInfinite
This isInfinite property of double true if the number is positive infinity or negative infinity; otherwise, false.
Return Type
double.isInfinite returns value of type bool
.
✐ Examples
1 Check if a number is infinite
In this example,
- We create a double variable
num
with the value 10.0. - We use the
isInfinite
property to check ifnum
is infinite. - We then print the result to standard output.
Dart Program
void main() {
double num = 10.0;
bool infinite = num.isInfinite;
print('Is $num infinite? $infinite');
}
Output
Is 10.0 infinite? false
2 Check if positive infinity is infinite
In this example,
- We create a double variable
infinity
initialized to positive infinity. - We use the
isInfinite
property to check ifinfinity
is infinite. - We then print the result to standard output.
Dart Program
void main() {
double infinity = double.infinity;
bool infinite = infinity.isInfinite;
print('Is $infinity infinite? $infinite');
}
Output
Is infinity infinite? true
3 Check if negative infinity is infinite
In this example,
- We create a double variable
negInfinity
initialized to negative infinity. - We use the
isInfinite
property to check ifnegInfinity
is infinite. - We then print the result to standard output.
Dart Program
void main() {
double negInfinity = -double.infinity;
bool infinite = negInfinity.isInfinite;
print('Is $negInfinity infinite? $infinite');
}
Output
Is -infinity infinite? true
Summary
In this Dart tutorial, we learned about isInfinite property of double: the syntax and few working examples with output and detailed explanation for each example.