Initializer

init(signOf:magnitudeOf:)

Creates a new floating-point value using the sign of one value and the magnitude of another. ある値の符号ともう一方の規模とを使って新しい浮動小数点値を作成します。

Declaration 宣言

init(signOf sign: Float, magnitudeOf mag: Float)

Parameters パラメータ

signOf

A value from which to use the sign. The result of the initializer has the same sign as signOf. それからの値が符号に使われることになります。イニシャライザの結果は、signOfと同じ符号を持ちます。

magnitudeOf

A value from which to use the magnitude. The result of the initializer has the same magnitude as magnitudeOf. そこからの値が規模に使われることになります。イニシャライザの結果は、magnitudeOfと同じ規模を持ちます。

Discussion 解説

The following example uses this initializer to create a new Double instance with the sign of a and the magnitude of b: 以下の例は、このイニシャライザを使って新しいDoubleインスタンスをaの符号と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. このイニシャライザは、IEEE 754 copysign演算を実装します。

Relationships 関係

From Protocol 由来プロトコル

See Also 参照

Converting Floating-Point Values 浮動小数点値の変換