Clojure-arithmetic-operators
提供:Dev Guides
Clojure-算術演算子
Clojure言語は、通常の算術演算子を任意の言語としてサポートします。 Clojureで使用できる算術演算子は次のとおりです。
Operator | Description | Example |
---|---|---|
+ | Addition of two operands | (+ 1 2) will give 3 |
− | Subtracts second operand from the first | (- 2 1) will give 1 |
* | Multiplication of both operands | (* 2 2) will give 4 |
/ | Division of numerator by denominator | (float (/3 2)) will give 1.5 |
inc | Incremental operators used to increment the value of an operand by 1 | inc 5 will give 6 |
dec | Incremental operators used to decrement the value of an operand by 1 | dec 5 will give 4 |
max | Returns the largest of its arguments | max 1 2 3 will return 3 |
min | Returns the smallest of its arguments | min 1 2 3 will return 1 |
rem | Remainder of dividing the first number by the second | rem 3 2 will give 1 |
例
次のコードスニペットは、さまざまな演算子の使用方法を示しています。
上記のプログラムは、次の出力を生成します。