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,

  1. We create a double variable num with the value 10.0.
  2. We use the isInfinite property to check if num is infinite.
  3. 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,

  1. We create a double variable infinity initialized to positive infinity.
  2. We use the isInfinite property to check if infinity is infinite.
  3. 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,

  1. We create a double variable negInfinity initialized to negative infinity.
  2. We use the isInfinite property to check if negInfinity is infinite.
  3. 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.