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

truncatingRemainder(dividingBy:)

Returns the remainder of this value divided by the given value using truncating division. 切り捨て除算を使って与えられた値で除算されたこの値の余りを返します。

Declaration 宣言

func truncatingRemainder(dividingBy other: Float) -> Float

Parameters パラメータ

other

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

Return Value 戻り値

The remainder of this value divided by other using truncating division. 切り捨て除算を使ってotherで除算されたこの値の余りを返します。

Discussion 解説

Performing truncating division with floating-point values results in a truncated integer quotient and a remainder. For values x and y and their truncated integer quotient q, the remainder r satisfies x == y * q + r. 不動小数点値で切り捨て除算を実行することは、切り捨てられる整数指数と余りという結果になります。値xyおよび切り捨てられる整数指数qに対して、余りrx == y * q + rを満足させます。

The following example calculates the truncating remainder of dividing 8.625 by 0.75: 以下の例は、8.625を0.75で除算することの切り捨てられる余りを計算します。


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


let q = (x / 0.75).rounded(.towardZero)
// q == 11.0
let r = x.truncatingRemainder(dividingBy: 0.75)
// r == 0.375


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

If this value and other are both finite numbers, the truncating remainder has the same sign as this value and is strictly smaller in magnitude than other. The truncatingRemainder(dividingBy:) method is always exact. この値とotherが両方とも有限の数ならば、切り捨てられる余りはこの値と同じ符号を持ち、そして厳密にotherより小さい規模になります。truncatingRemainder(dividingBy:)メソッドは常に正確です。

See Also 参照

Performing Calculations 計算の実行