实例方法
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 Int64 nonzeroBitCount用法及代码示例
- Swift Int64 -(_:)用法及代码示例
- Swift Int64 leadingZeroBitCount用法及代码示例
- Swift Int64 quotientAndRemainder(dividingBy:)用法及代码示例
- Swift Int64 !=(_:_:)用法及代码示例
- Swift Int64 &=(_:_:)用法及代码示例
- Swift Int64 -=(_:_:)用法及代码示例
- Swift Int64 ~(_:)用法及代码示例
- Swift Int64 <<(_:_:)用法及代码示例
- Swift Int64 init(integerLiteral:)用法及代码示例
- Swift Int64 multipliedFullWidth(by:)用法及代码示例
- Swift Int64 -(_:_:)用法及代码示例
- Swift Int64 trailingZeroBitCount用法及代码示例
- Swift Int64 ...(_:)用法及代码示例
- Swift Int64 init(truncatingIfNeeded:)用法及代码示例
- Swift Int64 %(_:_:)用法及代码示例
- Swift Int64 &-(_:_:)用法及代码示例
- Swift Int64 ..<(_:_:)用法及代码示例
- Swift Int64 /(_:_:)用法及代码示例
- Swift Int64 /=(_:_:)用法及代码示例
- Swift Int64 init(_:)用法及代码示例
- Swift Int64 ^(_:_:)用法及代码示例
- Swift Int64 &*(_:_:)用法及代码示例
- Swift Int64 &+=(_:_:)用法及代码示例
- Swift Int64 random(in:)用法及代码示例
注:本文由纯净天空筛选整理自apple.com大神的英文原创作品 Int64 negate()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。