實例方法
form
formRemainder(dividingBy:)
將此值替換為自身除以給定值的餘數。
聲明
mutating func formRemainder(dividingBy other: Float16)
參數
other
除此值時要使用的值。
詳述
對於兩個有限值 x
和 y
,將 x
除以 y
的餘數 r
滿足 x == y * q + r
,其中 q
是最接近 x / y
的整數。如果x / y
恰好在兩個整數之間,則選擇q
為偶數。請注意,q
是 not
x / y
以浮點算術計算的,並且 q
可能無法以任何可用的整數類型表示。
以下示例計算 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
如果此值和 other
是有限數,則餘數在封閉範圍內 -abs(other / 2)...abs(other / 2)
。 formRemainder(dividingBy:)
方法總是準確的。
可用版本
iOS 14.0+, iPadOS 14.0+, macOS 11.0+, Mac Catalyst 14.0+, tvOS 14.0+, watchOS 7.0+
相關用法
- Swift Float16 formTruncatingRemainder(dividingBy:)用法及代碼示例
- Swift Float16 ...(_:_:)用法及代碼示例
- Swift Float16 init(sign:exponent:significand:)用法及代碼示例
- Swift Float16 binade用法及代碼示例
- Swift Float16 radix用法及代碼示例
- Swift Float16 /(_:_:)用法及代碼示例
- Swift Float16 -(_:_:)用法及代碼示例
- Swift Float16 magnitude用法及代碼示例
- Swift Float16 isZero用法及代碼示例
- Swift Float16 squareRoot()用法及代碼示例
- Swift Float16 truncatingRemainder(dividingBy:)用法及代碼示例
- Swift Float16 isTotallyOrdered(belowOrEqualTo:)用法及代碼示例
- Swift Float16 negate()用法及代碼示例
- Swift Float16 init(integerLiteral:)用法及代碼示例
- Swift Float16 *(_:_:)用法及代碼示例
- Swift Float16 isNaN用法及代碼示例
- Swift Float16 ..<(_:)用法及代碼示例
- Swift Float16 -(_:)用法及代碼示例
- Swift Float16 init(exactly:)用法及代碼示例
- Swift Float16 +(_:)用法及代碼示例
- Swift Float16 rounded(_:)用法及代碼示例
- Swift Float16 init(signOf:magnitudeOf:)用法及代碼示例
- Swift Float16 init(_:)用法及代碼示例
- Swift Float16 minimumMagnitude(_:_:)用法及代碼示例
- Swift Float16 sign用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Float16 formRemainder(dividingBy:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。