Initializer

init(signOf:magnitudeOf:)

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

Declaration

init(signOf: Double, magnitudeOf: Double)

Parameters

signOf

A value from which to use the sign. The result of the initializer has the same sign as signOf.

magnitudeOf

A value from which to use the magnitude. The result of the initializer has the same magnitude as magnitudeOf.

Discussion

The following example uses this initializer to create a new Double instance with the sign of a and the magnitude of b:

let a = -21.5
let b = 305.15
let c = Double(signOf: a, magnitudeOf: b)
print(c)
// Prints "-305.15"

This initializer implements the IEEE 754 copysign operation.

See Also

Converting Floating-Point Values

init<Source>(Source)

Creates a new instance from the given value, rounded to the closest possible representation.

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(CGFloat)

Creates a new instance initialized to the given value.

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

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

init<Source>(Source)

Creates a new value, rounded to the closest possible representation.