What is the Double.exponent property in Swift?

Overview

The Double.exponent property of a value of type double in Swift is the exponent of a floating-point value. When we speak of exponents, we are referring to the integer part of the logarithm of the value’s magnitude.

Syntax

Double.exponent

Return value

The value returned is the exponent of the double value. This returned value is an integer.

Code example

// create some double values
let d1 = 12.44
let d2 = 1.23333
let d3 = 100.1
let d4 = 1.0
// print the exponents
print(d1.exponent)
print(d2.exponent)
print(d3.exponent)
print(d4.exponent)

Code explanation

In the code above,

  • In lines 2-5, we create the double values or the floating-point numbers.
  • In lines 8-11, we print the exponents of the double values.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources