数学演算子
SenseTalkは、数多くの数学演算子を提供します。以下で概要を説明します。
+
, Plus
演算子
Behavior: 二つの数字または数字のリストを足します。
構文:
operand1 + operand2
operand1 plus operand2
例:
put 12 + 97 into someSum
例:
put a squared plus b squared into sumOfSquares
例:
put [12,8] + [4,7] into vectorSum
-
, Minus
演算子
Behavior: 一つの数字または数字のリストから別の数字またはリストを引きます。日付/時間から別の日付/時間を引くと、その差分が秒単位の時間間隔として与えられます。
構文:
operand1 - operand2
operand1 minus operand2
例:
put c^2 - sumOfSquares into difference
例:
put (1,3,5,6) - (1,1,0,2) into diffList
*
, Times
, Multiplied By
演算子
Behavior: 二つの数値やリストを掛け算します、またはリストをスカラーで掛け算します。等しい長さの二つのリストを使って使用すると、結果は二つのリストの対応する要素の積の一連のものになります。一つのオペランドがリストで、もう一つが単一(スカラー)の値である場合、結果は、各元のリストの要素をスカラー値で掛け算した値のリストになります。
構文 :
operand1 * operand2
operand1 times operand2
operand1 multiplied by operand2
例:
put 2 * radius into diameter
例:
put pi times diameter into circumference
例:
put [1,2,3,4] * [2,2,1,3]-- result is [2,4,3,12]
例:
put [1,2,3md ,4] * 4 -- result is [4,8,12,16]
例:
put 7 multiplied by 3 -- result is 21