操作符
*(_:
*(_:_:)
将两个值相乘并产生它们的乘积。
声明
static func * (lhs: UInt64, rhs: UInt64) -> UInt64
参数
lhs
要相乘的第一个值。
rhs
要相乘的第二个值。
详述
乘法运算符 (*
) 计算其两个参数的乘积。例如:
2 * 3 // 6
100 * 21 // 2100
-10 * 15 // -150
3.5 * 2.25 // 7.875
您不能将*
与不同类型的参数一起使用。要将不同类型的值相乘,请将其中一个值转换为另一个值的类型。
let x: Int8 = 21
let y: Int = 1000000
Int(x) * y // 21000000
两个参数的乘积必须可以在参数的类型中表示。在以下示例中,21 * 21
的结果大于可表示的最大 Int8
值:
x * 21 // Overflow error
如果您想退出溢出检查并在发生溢出时包装结果,请使用溢出乘法运算符 (&*
)。
x &* 21 // -115
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
相关用法
- Swift UInt64 *=(_:_:)用法及代码示例
- Swift UInt64 random(in:using:)用法及代码示例
- Swift UInt64 /(_:_:)用法及代码示例
- Swift UInt64 ^=(_:_:)用法及代码示例
- Swift UInt64 ^(_:_:)用法及代码示例
- Swift UInt64 ..<(_:_:)用法及代码示例
- Swift UInt64 &<<=(_:_:)用法及代码示例
- Swift UInt64 init(_:radix:)用法及代码示例
- Swift UInt64 &-(_:_:)用法及代码示例
- Swift UInt64 &>>(_:_:)用法及代码示例
- Swift UInt64 &(_:_:)用法及代码示例
- Swift UInt64 /=(_:_:)用法及代码示例
- Swift UInt64 ==(_:_:)用法及代码示例
- Swift UInt64 >>=(_:_:)用法及代码示例
- Swift UInt64 random(in:)用法及代码示例
- Swift UInt64 &>>=(_:_:)用法及代码示例
- Swift UInt64 &=(_:_:)用法及代码示例
- Swift UInt64 trailingZeroBitCount用法及代码示例
- Swift UInt64 &+=(_:_:)用法及代码示例
- Swift UInt64 ...(_:)用法及代码示例
- Swift UInt64 >>(_:_:)用法及代码示例
- Swift UInt64 multipliedFullWidth(by:)用法及代码示例
- Swift UInt64 leadingZeroBitCount用法及代码示例
- Swift UInt64 &*=(_:_:)用法及代码示例
- Swift UInt64 |=(_:_:)用法及代码示例
注:本文由纯净天空筛选整理自apple.com大神的英文原创作品 UInt64 *(_:_:)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。