Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

swift
communitycreator

What is the Double.isNormal property in Swift?

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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
Check if Double values are normal in swift

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.

RELATED TAGS

swift
communitycreator

CONTRIBUTOR

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring