实例方法
negate()
用它的加法倒数替换这个值。
声明
mutating func negate()
详述
以下示例使用 negate()
方法来否定整数 x
的值:
var x = 21
x.negate()
// x == -21
结果值必须在值的类型内可表示。特别是,对有符号、固定宽度整数类型的最小值求反会导致无法表示的值。
var y = Int8.min
y.negate()
// Overflow error
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
相关用法
- Swift Int8 nonzeroBitCount用法及代码示例
- Swift Int8 ~(_:)用法及代码示例
- Swift Int8 *=(_:_:)用法及代码示例
- Swift Int8 -(_:_:)用法及代码示例
- Swift Int8 %(_:_:)用法及代码示例
- Swift Int8 |=(_:_:)用法及代码示例
- Swift Int8 ...(_:_:)用法及代码示例
- Swift Int8 init(truncatingIfNeeded:)用法及代码示例
- Swift Int8 >>(_:_:)用法及代码示例
- Swift Int8 /(_:_:)用法及代码示例
- Swift Int8 ==(_:_:)用法及代码示例
- Swift Int8 |(_:_:)用法及代码示例
- Swift Int8 magnitude用法及代码示例
- Swift Int8 init(integerLiteral:)用法及代码示例
- Swift Int8 init(exactly:)用法及代码示例
- Swift Int8 <<=(_:_:)用法及代码示例
- Swift Int8 &(_:_:)用法及代码示例
- Swift Int8 trailingZeroBitCount用法及代码示例
- Swift Int8 init(_:radix:)用法及代码示例
- Swift Int8 &+(_:_:)用法及代码示例
- Swift Int8 ...(_:)用法及代码示例
- Swift Int8 >>=(_:_:)用法及代码示例
- Swift Int8 &<<=(_:_:)用法及代码示例
- Swift Int8 &<<(_:_:)用法及代码示例
- Swift Int8 random(in:)用法及代码示例
注:本文由纯净天空筛选整理自apple.com大神的英文原创作品 Int8 negate()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。