实例方法
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:)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。