Initializer

init(sign:exponent:significand:)

Creates a new value from the given sign, exponent, and significand. 与えられた符号、指数、そして仮数から新しい値を作成します。

Declaration 宣言

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

Parameters パラメータ

sign

The sign to use for the new value. 新しい値に対して使うための符号。

exponent

The new value’s exponent. 新しい値の持つ指数。

significand

The new value’s significand. 新しい値の持つ仮数。

Discussion 解説

The following example uses this initializer to create a new Double instance. Double is a binary floating-point type that has a radix of 2. 以下の例は、このイニシャライザを使って新しいDoubleインスタンスを作成します。Doubleはバイナリ浮動小数点型で2の基数を持ちます。


let x = Double(sign: .plus, exponent: -2, significand: 1.5)
// x == 0.375

This initializer is equivalent to the following calculation, where ** is exponentiation, computed as if by a single, correctly rounded, floating-point operation: このイニシャライザは次の計算に相当し、そこで**は乗算で、まるで単精度の、正しく丸められた、浮動小数点演算のように計算されます:


let sign: FloatingPointSign = .plus
let exponent = -2
let significand = 1.5
let y = (sign == .minus ? -1 : 1) * significand * Double.radix ** exponent
// y == 0.375

As with any basic operation, if this value is outside the representable range of the type, overflow or underflow occurs, and zero, a subnormal value, or infinity may result. In addition, there are two other edge cases: あらゆる基本的演算でのように、この値がその型の表現可能な範囲の外側ならば、オーバーフローまたはアンダーフローが起こります、そしてゼロ、サブノーマル値、または無限大が結果となるでしょう。加えて、2つの別の境界事例があります:

  • If the value you pass to significand is zero or infinite, the result is zero or infinite, regardless of the value of exponent. あなたがsignificandに渡す値がゼロまたは無限大ならば、結果はゼロまたは無限大です、exponentの値に関係なく。

  • If the value you pass to significand is NaN, the result is NaN. あなたがsignificandに渡す値がNaNならば、結果はNaNです。

For any floating-point value x of type F, the result of the following is equal to x, with the distinction that the result is canonicalized if x is in a noncanonical encoding: 何らかの浮動小数点値型Fxに対して、以下の結果はxと等しいです、その違いはxが非正準符号化になるならば結果は正準化されることです。


let x0 = F(sign: x.sign, exponent: x.exponent, significand: x.significand)

This initializer implements the scaleB operation defined by the IEEE 754 specification. このイニシャライザは、IEEE 754仕様で定義されるscaleB演算を実装します。

Relationships 関係

From Protocol 由来プロトコル

See Also 参照

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