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