Skip to main content

Numbers

Integers

Mew's integer types represent a "whole" number.

1
-2
0x2A
0xDEADBEEF

Signed integers

LengthTypeAliasRange
8-biti8-128 to 127
16-biti16-32,768 to 32,767
32-biti32int-2,147,483,648 to 2,147,483,647
64-biti64-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

Unsigned integers

LengthTypeRange
8-bitu80 to 255
16-bitu160 to 65,535
32-bitu320 to 4,294,967,295
64-bitu640 to 18,446,744,073,709,551,615

Operators

1 + 2 // => 3
3 - 2 // => 1
3 * 3 // => 9
9 / 3 // => 3
9 % 3 // => 0

1 > 2 // => false
1 < 2 // => true
1 >= 2 // => false
1 <= 2 // => true

Floating Point Numbers

Mew's float types represents a number with a decimal point.

1.0
-2.0
LengthTypeApproximate rangePrecision
32-bitf32N/A~6-9 digits
64-bitf64N/A~15-17 digits

Operators

1.0 + 2.0 // => 3.0
3.0 - 2.0 // => 1.0
3.0 * 3.0 // => 9.0
9.0 / 3.0 // => 3.0
9.0 % 3.0 // => 0.0

1.0 > 2.0 // => false
1.0 < 2.0 // => true
1.0 >= 2.0 // => false
1.0 <= 2.0 // => true

Suffixes

You can use the types name as a suffix to specify what the integer/floating point kind:

let foo = 32u8;
let bar = 128.32i16;

Coercion

Example: Performing an add (+) of a i8 and a u32, results in a i64.

i8i16i32i64u8u16u32u64f32f64char
i8i32i32i32i64i32i32i64f32f64i32
i16i32i32i32i64i32i32i64f32f64i32
i32i32i32i32i64i32i32i64f32f64i32
i64i64i64i64i64i64i64i64f32f64i64
u8i32i32i32i64i32i32u32u64f32f64i32
u16i32i32i32i64i32i32u32u64f32f64i32
u32i64i64i64i64u32u32u32u64f32f64u32
u64u64u64u64u64f32f64u64
f32f32f32f32f32f32f32f32f32f32f64f32
f64f64f64f64f64f64f64f64f64f64f64f64
chari32i32i32i64i32i32u32u64f32f64i32

Casting

Example: i8 can be cast to i32 implicitly.
Example: i8 can only be cast to u8 explicitly.

i8i16i32i64u8u16u32u64f32f64char
i8iiiieeeeiie
i16iiieeeeiie
i32iieeeeiie
i64ieeeeiie
u8eiiiiiiiiie
u16eeiiiiiiie
u32eeeiiiiie
u64eeeeiiie
f32eeeeeeeeiie
f64iiiiiiiiie
chareeiieiiiiii

Legend

CharacterMeaning
iImplicit cast
uExplicit cast
[blank]Not possible