Instance Method インスタンスメソッド

formRemainder(dividingBy:)

Replaces this value with the remainder of itself divided by the given value. それ自身を与えられた値で除算した余りでこの値を置き換えます。

Declaration 宣言

mutating func formRemainder(dividingBy other: Float)

Parameters パラメータ

other

The value to use when dividing this value. この値を除算するときに使うための値。

Discussion 解説

For two finite values x and y, the remainder r of dividing x by y satisfies x == y * q + r, where q is the integer nearest to x / y. If x / y is exactly halfway between two integers, q is chosen to be even. Note that q is not x / y computed in floating-point arithmetic, and that q may not be representable in any available integer type. 2つの有限値xyに対して、xyで割った余りrx == y * q + rを満足させます、ここでqx / yに最も近い整数です。x / yが正確に2つの整数の間の中ほどならば、qは偶数である方を選ばれます。qが浮動小数点算術で計算されるx / yではないこと、そしてqは何らかの利用可能な整数型において表現可能でないかもしれないことに注意してください

The following example calculates the remainder of dividing 8.625 by 0.75: 以下の例は、8.625を0.75で割ることの余りを計算します:


var x = 8.625
print(x / 0.75)
// Prints "11.5"


let q = (x / 0.75).rounded(.toNearestOrEven)
// q == 12.0
x.formRemainder(dividingBy: 0.75)
// x == -0.375


let x1 = 0.75 * q + x
// x1 == 8.625

If this value and other are finite numbers, the remainder is in the closed range -abs(other / 2)...abs(other / 2). The formRemainder(dividingBy:) method is always exact. この値とotherが有限数ならば、あまりは完結範囲-abs(other / 2)...abs(other / 2)の中に入ります。formRemainder(dividingBy:)メソッドは常に正確です。

Relationships 関係

From Protocol 由来プロトコル

See Also 参照

Performing Calculations 計算の実行