Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

nan
swift
double
communitycreator

What is Double.isNaN 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.

Answers Code

Overview

Double.isNaN property in Swift is used to check if an instance of type double is NaN (Not a Number).

Syntax

Double.isNaN

Parameter

This function does not take any parameters.

Return value

The value returned is a boolean value.

Code example

// create some values
let d1 = 1.2
let d2 = 0.0
let d3 = Double.infinity * 0.0
let d4 = Double.infinity
let d5 = Double.nan * 2
// check if Not a Number
print(d1.isNaN) // false
print(d2.isNaN) // false
print(d3.isNaN) // true
print(d4.isNaN) // false
print(d5.isNaN) // true
Check if number values are decimal

Explanation

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

RELATED TAGS

nan
swift
double
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.

Answers Code
Keep Exploring