Structure

Double

A double-precision, floating-point value type.

Topics

Converting Integers

init(Int)

Creates the closest representable value to the given integer.

init(Int8)

Creates the closest representable value to the given integer.

init(Int16)

Creates the closest representable value to the given integer.

init(Int32)

Creates the closest representable value to the given integer.

init(Int64)

Creates the closest representable value to the given integer.

init(UInt)

Creates the closest representable value to the given integer.

init(UInt8)

Creates the closest representable value to the given integer.

init(UInt16)

Creates the closest representable value to the given integer.

init(UInt32)

Creates the closest representable value to the given integer.

init(UInt64)

Creates the closest representable value to the given integer.

Converting Strings

init?<S>(S)

Creates a new instance from the given string.

Converting Floating-Point Values

init(Double)

Creates a new instance initialized to the given value.

init(Float)

Creates a new instance that approximates the given value.

init(Float80)

Creates a new instance that approximates the given value.

init(NSNumber)Deprecated
init(sign: FloatingPointSign, exponent: Int, significand: Double)

Creates a new value from the given sign, exponent, and significand.

init(signOf: Double, magnitudeOf: Double)

Creates a new floating-point value using the sign of one value and the magnitude of another.

Converting Exactly

These initializers result in nil if the value passed can't be represented without any loss of precision.

init?(exactly: Double)

Creates a new instance initialized to the given value, if it can be represented without rounding.

init?(exactly: Float)

Creates a new instance initialized to the given value, if it can be represented without rounding.

init?(exactly: Float80)

Creates a new instance initialized to the given value, if it can be represented without rounding.

init?(exactly: Int)

Creates a value that exactly represents the given integer.

init?(exactly: Int16)

Creates a value that exactly represents the given integer.

init?(exactly: Int8)

Creates a value that exactly represents the given integer.

init?(exactly: Int32)

Creates a value that exactly represents the given integer.

init?(exactly: Int64)

Creates a value that exactly represents the given integer.

init?(exactly: UInt)

Creates a value that exactly represents the given integer.

init?(exactly: UInt8)

Creates a value that exactly represents the given integer.

init?(exactly: UInt16)

Creates a value that exactly represents the given integer.

init?(exactly: UInt32)

Creates a value that exactly represents the given integer.

init?(exactly: UInt64)

Creates a value that exactly represents the given integer.

Performing Calculations

Floating-Point Operators for Double

Perform arithmetic and bitwise operations or compare values.

func addingProduct(Double, Double)

Returns the result of adding the product of the two given values to this value, computed without intermediate rounding.

func addProduct(Double, Double)

Adds the product of the two given values to this value in place, computed without intermediate rounding.

func squareRoot()

Returns the square root of the value, rounded to a representable value.

func formSquareRoot()

Replaces this value with its square root, rounded to a representable value.

func remainder(dividingBy: Double)

Returns the remainder of this value divided by the given value.

func truncatingRemainder(dividingBy: Double)

Returns the remainder of this value divided by the given value using truncating division.

func formTruncatingRemainder(dividingBy: Double)

Replaces this value with the remainder of itself divided by the given value using truncating division.

func negate()

Replaces this value with its additive inverse.

func negate()

Replaces this value with its additive inverse.

Rounding

func rounded()

Returns this value rounded to an integral value using “schoolbook rounding.”

func rounded(FloatingPointRoundingRule)

Returns this value rounded to an integral value using the specified rounding rule.

func round()

Rounds this value to an integral value using “schoolbook rounding.”

func round(FloatingPointRoundingRule)

Rounds the value to an integral value using the specified rounding rule.

Comparing Doubles

Floating-Point Operators for Double

Perform arithmetic and bitwise operations or compare values.

func isEqual(to: Double)

Returns a Boolean value indicating whether this instance is equal to the given value.

func isLess(than: Double)

Returns a Boolean value indicating whether this instance is less than the given value.

func isLessThanOrEqualTo(Double)

Returns a Boolean value indicating whether this instance is less than or equal to the given value.

func isTotallyOrdered(belowOrEqualTo: Double)

Returns a Boolean value indicating whether this instance should precede or tie positions with the given value in an ascending sort.

static func minimum(Double, Double)

Returns the lesser of the two given values.

static func minimumMagnitude(Double, Double)

Returns the value with lesser magnitude.

static func maximum(Double, Double)

Returns the greater of the two given values.

static func maximumMagnitude(Double, Double)

Returns the value with greater magnitude.

Finding the Sign and Magnitude

var magnitude: Double

The magnitude of this value.

func abs<T>(T)

Returns the absolute value of x.

var sign: FloatingPointSign

The sign of the floating-point value.

Querying a Double

var ulp: Double

The unit in the last place of this value.

var significand: Double

The significand of the floating-point value.

var exponent: Int

The exponent of the floating-point value.

var nextUp: Double

The least representable value that compares greater than this value.

var nextDown: Double

The greatest representable value that compares less than this value.

var binade: Double

The floating-point value with the same sign and exponent as this value, but with a significand of 1.0.

Accessing Numeric Constants

static var pi: Double

The mathematical constant pi.

static var infinity: Double

Positive infinity.

static var greatestFiniteMagnitude: Double

The greatest finite number representable by this type.

static var nan: Double

A quiet NaN (“not a number”).

static var signalingNaN: Double

A signaling NaN (“not a number”).

static var ulpOfOne: Double

The unit in the last place of 1.0.

static var leastNormalMagnitude: Double

The least positive normal number.

Working with Binary Representation

var bitPattern: UInt64

The bit pattern of the value’s encoding.

var significandBitPattern: UInt64

The raw encoding of the value’s significand field.

var significandWidth: Int

The number of bits required to represent the value’s significand.

var exponentBitPattern: UInt

The raw encoding of the value’s exponent field.

static var significandBitCount: Int

The available number of fractional significand bits.

static var exponentBitCount: Int

The number of bits used to represent the type’s exponent.

static var radix: Int

The radix, or base of exponentiation, for this floating-point type.

init(bitPattern: UInt64)

Creates a new value with the given bit pattern.

init(sign: FloatingPointSign, exponentBitPattern: UInt, significandBitPattern: UInt64)

Creates a new instance from the specified sign and bit patterns.

init(nan: Double.RawSignificand, signaling: Bool)

Creates a NaN (“not a number”) value with the specified payload.

Querying a Double's State

var isZero: Bool

A Boolean value indicating whether the instance is equal to zero.

var isFinite: Bool

A Boolean value indicating whether this instance is finite.

var isInfinite: Bool

A Boolean value indicating whether the instance is infinite.

var isNaN: Bool

A Boolean value indicating whether the instance is NaN (“not a number”).

var isSignalingNaN: Bool

A Boolean value indicating whether the instance is a signaling NaN.

var isNormal: Bool

A Boolean value indicating whether this instance is normal.

var isSubnormal: Bool

A Boolean value indicating whether the instance is subnormal.

var isCanonical: Bool

A Boolean value indicating whether the instance’s representation is in the canonical form.

Describing a Double

var description: String

A textual representation of the value.

var debugDescription: String

A textual representation of the value, suitable for debugging.

var customMirror: Mirror

A mirror that reflects the Double instance.

var hashValue: Int

The number’s hash value.

Infrequently Used Functionality

init()

Creates a value initialized to zero.

init(floatLiteral: Double)

Creates a new value from the given floating-point literal.

init(integerLiteral: Int64)

Creates a new value from the given integer literal.

func advanced(by: Double)

Returns a new value advanced by the given distance.

func distance(to: Double)

Returns the distance from this value to the specified value.

See Also

Numeric Values

struct Int

A signed integer value type.

struct Float

A single-precision, floating-point value type.