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.
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources