Required Initializerswift 6.0.1Swift
init(signOf:magnitudeOf:)
Creates a new floating-point value using the sign of one value and the magnitude of another.
init(signOf: Self, magnitudeOf: Self)
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
.
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.
Other requirements
View members
Hide members
This section is hidden by default because it contains too many (57) members.
Type members
associatedtype Exponent
A type that can represent any written exponent.
init(Int
) Creates a new value, rounded to the closest possible representation.
init<Source>(Source
) Creates a new value, rounded to the closest possible representation.
init?<Source>(exactly: Source
) Creates a new value, if the given integer can be represented exactly.
init(sign: FloatingPointSign, exponent: Self.Exponent, significand: Self
) Creates a new value from the given sign, exponent, and significand.
static var greatestFiniteMagnitude: Self
The greatest finite number representable by this type.
static var infinity: Self
Positive infinity.
static var leastNonzeroMagnitude: Self
The least positive number.
static var leastNormalMagnitude: Self
The least positive normal number.
static var nan: Self
A quiet NaN (“not a number”).
static var pi: Self
The mathematical constant pi (π), approximately equal to 3.14159.
static var radix: Int
The radix, or base of exponentiation, for a floating-point type.
static var signalingNaN: Self
A signaling NaN (“not a number”).
static var ulpOfOne: Self
The unit in the last place of 1.0.
static func maximum(Self, Self
) -> Self Returns the greater of the two given values.
static func maximumMagnitude(Self, Self
) -> Self Returns the value with greater magnitude.
static func minimum(Self, Self
) -> Self Returns the lesser of the two given values.
static func minimumMagnitude(Self, Self
) -> Self Returns the value with lesser magnitude.
static func * (lhs: Self, rhs: Self
) -> Self Multiplies two values and produces their product, rounding to a representable value.
static func *= (lhs: inout Self, rhs: Self
) Multiplies two values and stores the result in the left-hand-side variable, rounding to a representable value.
static func + (lhs: Self, rhs: Self
) -> Self Adds two values and produces their sum, rounded to a representable value.
static func += (lhs: inout Self, rhs: Self
) Adds two values and stores the result in the left-hand-side variable, rounded to a representable value.
static func - (operand: Self
) -> Self Calculates the additive inverse of a value.
static func - (lhs: Self, rhs: Self
) -> Self Subtracts one value from another and produces their difference, rounded to a representable value.
static func -= (lhs: inout Self, rhs: Self
) Subtracts the second value from the first and stores the difference in the left-hand-side variable, rounding to a representable value.
static func / (lhs: Self, rhs: Self
) -> Self Returns the quotient of dividing the first value by the second, rounded to a representable value.
static func /= (lhs: inout Self, rhs: Self
) Divides the first value by the second and stores the quotient in the left-hand-side variable, rounding to a representable value.
Instance members
var exponent: Self.Exponent
The exponent of the floating-point value.
var floatingPointClass: FloatingPointClassification
The classification of this value.
var isCanonical: Bool
A Boolean value indicating whether the instance’s representation is in its canonical form.
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 isNormal: Bool
A Boolean value indicating whether this instance is normal.
var isSignalingNaN: Bool
A Boolean value indicating whether the instance is a signaling NaN.
var isSubnormal: Bool
A Boolean value indicating whether the instance is subnormal.
var isZero: Bool
A Boolean value indicating whether the instance is equal to zero.
var nextDown: Self
The greatest representable value that compares less than this value.
var nextUp: Self
The least representable value that compares greater than this value.
var sign: FloatingPointSign
The sign of the floating-point value.
var significand: Self
The significand of the floating-point value.
var ulp: Self
The unit in the last place of this value.
func addProduct(Self, Self
) Adds the product of the two given values to this value in place, computed without intermediate rounding.
func addingProduct(Self, Self
) -> Self Returns the result of adding the product of the two given values to this value, computed without intermediate rounding.
func formRemainder(dividingBy: Self
) Replaces this value with the remainder of itself divided by the given value.
func formSquareRoot(
) Replaces this value with its square root, rounded to a representable value.
func formTruncatingRemainder(dividingBy: Self
) Replaces this value with the remainder of itself divided by the given value using truncating division.
func isEqual(to: Self
) -> Bool Returns a Boolean value indicating whether this instance is equal to the given value.
func isLess(than: Self
) -> Bool Returns a Boolean value indicating whether this instance is less than the given value.
func isLessThanOrEqualTo(Self
) -> Bool Returns a Boolean value indicating whether this instance is less than or equal to the given value.
func isTotallyOrdered(belowOrEqualTo: Self
) -> Bool Returns a Boolean value indicating whether this instance should precede or tie positions with the given value in an ascending sort.
func negate(
) Replaces this value with its additive inverse.
func remainder(dividingBy: Self
) -> Self Returns the remainder of this value divided by the given value.
func round(FloatingPointRoundingRule
) Rounds the value to an integral value using the specified rounding rule.
func rounded(FloatingPointRoundingRule
) -> Self Returns this value rounded to an integral value using the specified rounding rule.
func squareRoot(
) -> Self Returns the square root of the value, rounded to a representable value.
func truncatingRemainder(dividingBy: Self
) -> Self Returns the remainder of this value divided by the given value using truncating division.