What is Double.isInfinite in Swift?

Overview

Double.isInfinte is used to indicate if a value of type double is infinite or not.

Syntax

Double.isInfinite

Parameter

This function does not take any parameter.

Return value

The value returned is a boolean value. It returns true if the value is infinite. Otherwise, it returns false.

Code example

// create some double values
let d1 = 1.233
let d2 = Double.infinity
let d3 = 0.9
let d4 = Double.infinity/0
// check if infinity
print(d1.isInfinite)
print(d2.isInfinite)
print(d3.isInfinite)
print(d4.isInfinite)

Explanation

  • Lines 2-5: We create some double values.
  • Lines 8-11: We check if the double values we created are infinite and print the results.

Free Resources