What is the Double.nextDown property of a double value in Swift?

Overview

The Double.nextDown property of a double value in Swift finds the greatest representable value that compares less than this value.

Syntax

Double.nextDown

Return value

This property returns the greatest representable value that compares less than the double value.

Code example

// Create some double values
let d1 = 2.3
let d2 = 0.0
let d3 = Double.infinity
let d4 = Double.nan
let d5 = -0.1
// Get the nextDown property values
print(d1.nextDown)
print(d2.nextDown)
print(d3.nextDown)
print(d4.nextDown)
print(d5.nextDown)

Explanation

  • Lines 2 to 6: We create some double values.
  • Line 9 to 13: We get the nextDown property of the Double instance values, and print them to the console.

Free Resources