# clojure-基本语法-数字类型

```user=> (+)
0
user=> (+ 1)
1
user=> (+ 1 2 3 4)
10
```

```user=> (- 1)
-1
user=> (- 10 2)
8
user=> (- 10 2 3 4)
1
```

```user=> (*)
1
user=> (* 1)
1
user=> (* 1 2 3)
6
user=> (* 0 1 2 3)
0
```

```user=> (/ 2)
1/2
user=> (/ 2 10)
1/5
user=> (/ 1 2 4 6)
1/48
```

```user=> (quot 10 3)
3
user=> (quot 11 3)
3
user=> (quot 12 3)
4
user=> (quot -5.9 3)
-1.0
user=> (quot 10 -3)
-3
user=> (quot 15 0)
ArithmeticException / by zero  clojure.lang.Numbers.quotient (Numbers.java:1764)
```

```user=> (= (/ 4 2) (quot 4 2))
true
user=> (= (/ 3 2) (quot 3 2))
false
```

```user=> (rem 10 9)
1
user=> (rem 2 2)
0
user=> (rem 10 -3)
1
```

```user=> (mod 10 9)
1
user=> (mod 2 2)
0
user=> (mod 10 -3)
-2
```

(rem 10 -3)和(mod 10 -3)结果不一致，分别为1，-2。-2是如何得到的？由于（rem 10 -3）的返回值为1，那么（mod 10 -3）的返回值为(+ 1 (rem 10 -3))=-2

```(defn mod
"Modulus of num and div. Truncates toward negative infinity."
:static true}
[num div]
(let [m (rem num div)]
(if (or (zero? m) (= (pos? num) (pos? div)))
m
(+ m div))))
```

```user=> (inc 1)
2
user=> (inc -1)
0
```

```user=> (dec 1)
0
user=> (dec -1)
-2
```

```user=> (max 5 -1 2 3)
5
```

```user=> (min 5 -1 2 3.9)
-1
```

```user=> (with-precision 10 (/ 1M 3))
0.3333333333M
user=> (with-precision 2 (/ 100M 3))
33M
user=> (with-precision 4 (/ 100M 3))
33.33M
```

```user=> (= 1)
true
user=> (= 1 1)
true
user=> (= 1 1.0)
false
user=> (= 1 2)
false
user=> (= 1 1 1)
true
user=> (= 1 1 2)
false
user=> (= nil nil)
true
```

```user=> (== 1 1.0)
true
user=> (== :foo)
true
user=> (== nil)
true
```

```user=> (not= 1 1)
false
user=> (not= 1 2)
true
user=> (not= 1 1.0)
true
user=> (not= true true)
false
user=> (not= true false)
true
user=> (not= true true false)
true
```

```user=> (< 5 10)
true
user=> (< 5 10 9)
false
user=> (< 1)
true
```

```user=> (> 5 2)
true
user=> (> 5 10 9)
false
user=> (> 1)
true
```

```user=> (>= 10 5 5)
true
```

```user=> (<= 2 5 5)
true
```

0检查zero?：
0检查函数 (zero?) 接受一个数值类型参数，如果是0返回true，否则返回false
```user=> (zero? 0.0)
true
```

```user=> (pos? -2)
false
user=> (pos? 1.2)
true
```

```user=> (neg? -3)
true
user=> (neg? 0)
false
```

```user=> (even? 10)
true
user=> (even? 3)
false
```

```user=> (odd? 10)
false
user=> (odd? 3)
true
```

```user=> (number? 3.2)
true
user=> (number? "2")
false
```

```byte  Coerce to byte.
short  Coerce to short.
int  Coerce to int.
long  Coerce to long.
float  Coerce to float.
double  Coerce to double.
bigint  Coerce to BigInteger.
bigdec  Coerce to BigDecimal.
num  Coerce to Number.
rationalize  returns the rational value of num
```

```user=> (double 12)
12.0
user=> (short 10000)
10000
user=> (short 22.2)
22
user=> (int 22.2)
22
user=> (long 22.2)
22
user=> (float 100)
100.0
user=> (bigint 1000000000)
1000000000N
user=> (bigdec 100000)
100000M
user=> (num 1.11)
1.11
user=> (rationalize 0.5)
1/2
```

clojure-基本语法-数字类型

• 0

开心

• 0

板砖

• 0

感动

• 0

有用

• 0

疑问

• 0

难过

• 0

无聊

• 0

震惊

using System; using System.Collections.Generic; using System.Text; using System.Collections;

1.String是字符串的对象包装类型,可以如下方式使用String构造函数来创建. var stringobject = new S
Java 入门 二 （基本数据类型与引用数据类型的区别） 首先，想了解 基本数据类型与引用数据类型的区
JNI的类型 1、基本数据类型 以下是java的基本数据类型和jni中的基本数据类型的比较，及各类型的字节