Related Tags

double
finite
swift
communitycreator

# How to check if a double value is finite in Swift

Theodore Kelechukwu Onyejiaku

### Overview

When we want to check if an object of type double is finite or infinite, we can use the Double.isFinite property.

### Syntax

Double.isFinite


### Return value

The value returned is a boolean value. We get true if Double is a finite value. Otherwise, we get false.

### Code example

// create some double values
let d1 = 12.44
let d2 = Double.infinity
let d3 = Double.infinity / 0.4
let d4 = 0.1

// print the exponents
print(d1.isFinite)
print(d2.isFinite)
print(d3.isFinite)
print(d4.isFinite)
Check if a Double value is finite in Swift

### Explanation

• Lines 2-5: We create some double values.
• Lines 8-11: We check if the double values we created are finite values and we print the results to the console.

RELATED TAGS

double
finite
swift
communitycreator

CONTRIBUTOR

Theodore Kelechukwu Onyejiaku
RELATED COURSES

View all Courses

Keep Exploring

Learn in-demand tech skills in half the time