数字类型

Sized Number

The default integer type is Integer, short alias is int.

It is a reference type, which represents an arbitrary precision integer.

If you want some fixed size number, you can write 255u8

Here are some other primitive numeric type

postfixdescriptionexample
u8unsigned 8 bit integer255u8
i8signed 8 bit integer-127i8
u16unsigned 16 bit integer65535u16
i16signed 16 bit integer-32767i16
b16truncated 32-bit float0.5f16
u32unsigned 32 bit integer4294967295u32
i32signed 32 bit integer-2147483647i32
f32single precision float0.5f32
u64unsigned 64 bit integer18446744073709551615u64
i64signed 64 bit integer-9223372036854775807i64
f64double precision float0.5f64
u128unsigned 128 bit integer340282366920938463463374607431768211455u128
i128signed 128 bit integer-170141183460469231731687303715884105727i128
d128128 bit decimal0.5d128

Unit number

In addition, you can customize other postfix number types

1m + 2cm
1kg * 9.8`m/s^2`