- 绝对值获取方式
var count = -10
count.negate()
print(count)
count = -30
print(count.magnitude) // 推荐使用
count = -20
print(abs(count))
输出结果:
10
30
20
- 数据的符号判断 (1代表是正数, 0代表是0,-1代表是负数)
var a = 10
var b = 0
var c = -20
print(a.signum())
print(b.signum())
print(c.signum())
输出结果:
1
0
-1
- 整型的最大最小值
print(Int.max)
print(Int.zero)
print(Int.min)
输出结果:
9223372036854775807
0
-9223372036854775808