實例屬性
magnitude
這個值的大小。
聲明
var magnitude: UInt16 { get }
詳述
對於任何數值 x
, x.magnitude
是 x
的絕對值。您可以在更簡單的無符號值操作中使用magnitude
屬性,例如打印整數的值,這隻是在絕對值前麵打印一個“-”字符。
let x = -200
// x.magnitude == 200
當您需要查找絕對值時,全局abs(_:)
函數提供了更熟悉的語法。此外,由於 abs(_:)
始終返回相同類型的值,即使在通用上下文中,也鼓勵使用函數而不是 magnitude
屬性。
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
相關用法
- Swift Int16 multipliedFullWidth(by:)用法及代碼示例
- Swift Int16 ..<(_:)用法及代碼示例
- Swift Int16 random(in:using:)用法及代碼示例
- Swift Int16 ^=(_:_:)用法及代碼示例
- Swift Int16 init(_:radix:)用法及代碼示例
- Swift Int16 +(_:)用法及代碼示例
- Swift Int16 %(_:_:)用法及代碼示例
- Swift Int16 /=(_:_:)用法及代碼示例
- Swift Int16 <<=(_:_:)用法及代碼示例
- Swift Int16 init(truncatingIfNeeded:)用法及代碼示例
- Swift Int16 <<(_:_:)用法及代碼示例
- Swift Int16 random(in:)用法及代碼示例
- Swift Int16 ...(_:)用法及代碼示例
- Swift Int16 init(_:)用法及代碼示例
- Swift Int16 >>(_:_:)用法及代碼示例
- Swift Int16 init(clamping:)用法及代碼示例
- Swift Int16 *(_:_:)用法及代碼示例
- Swift Int16 &-=(_:_:)用法及代碼示例
- Swift Int16 quotientAndRemainder(dividingBy:)用法及代碼示例
- Swift Int16 |(_:_:)用法及代碼示例
- Swift Int16 -(_:_:)用法及代碼示例
- Swift Int16 ^(_:_:)用法及代碼示例
- Swift Int16 &*(_:_:)用法及代碼示例
- Swift Int16 &<<(_:_:)用法及代碼示例
- Swift Int16 init(exactly:)用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Int16 magnitude。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。