What is the Double.isNormal property in Swift?

Overview

The isNormal property of an instance of type double in Swift is used to check if the instance is normal. A normal value is a finite number that uses full precision available to it.

Syntax

Double.isNormal

Return value

The value returned is a boolean. It is true if the value is normal. Otherwise, false is returned.

Code example

// create double values
let x1 = 34.444
let x2 = 0.0
let x3 = 1.2
let x4 = Double.infinity
let x5 = -0.555
// check if normal
print(x1.isNormal) // true
print(x2.isNormal) // false
print(x3.isNormal) // true
print(x4.isNormal) // false
print(x5.isNormal) // true

Explanation

  • Lines 2-6: We create some double values.
  • Lines 9-13: We check to see if the values are normal and print the results to the console.

Free Resources