What is Double.Infinity in Swift?

Overview

Double.infinity in Swift returns a positive infinity value. When compared, it is greater than all finite values and equal to infinite values.

Syntax

Double.infinity

Return value

This method returns an infinity value inf.

Code example

Error: Code Widget Crashed, Please Contact Support

Explanation

  • Line 2: We declare the infinity value using Double.infinity, and store it in the variable infValue.
  • Lines 8 to 10: We compare the infinity value infValue with some other values and infinity itself.
  • Lines 13 to 15: We print the results of each comparison to the console.

Free Resources