Operator 演算子

*(_:_:)

Multiplies two values and produces their product. 2つの値を乗算してそれらの積を生成します。

Declaration 宣言

static func * (lhs: UInt8, rhs: UInt8) -> UInt8

Parameters パラメータ

lhs

The first value to multiply. 掛け合わされる第1の値。

rhs

The second value to multiply. 掛け合わされる第2の値。

Discussion 解説

The multiplication operator (*) calculates the product of its two arguments. For example: 乗算演算子(*)は、それの2つの引数の積を計算します。例えば:


2 * 3                   // 6
100 * 21                // 2100
-10 * 15                // -150
3.5 * 2.25              // 7.875

You cannot use * with arguments of different types. To multiply values of different types, convert one of the values to the other value’s type. あなたは、*をそれぞれが異なる型である引数で使うことはできません。異なる型の値を乗算するには、それらの値の一方を、他方の値の型へと変換してください。


let x: Int8 = 21
let y: Int = 1000000
Int(x) * y              // 21000000

The product of the two arguments must be representable in the arguments’ type. In the following example, the result of 21 * 21 is greater than the maximum representable Int8 value: 2つの引数の積は、引数の持つ型において表現可能でなければなりません。以下の例において、21 * 21の結果は、最大限表現可能なInt8値より大きいです:


x * 21                  // Overflow error

If you want to opt out of overflow checking and wrap the result in case of any overflow, use the overflow multiplication operator (&*). あなたがオーバーフロー検査を取りやめて、あらゆるオーバーフローの場合に結果をラップしたいならば、オーバーフロー乗算演算子(&*)を使ってください。


x &* 21                // -115

Relationships 関係

From Protocol 由来プロトコル