Skip to Content

Int

int is not the only integer type; it is merely the default type for integer literals. MushScript’s integers come in the following widths:

FamilyTypesLiteral suffix
Signedint8 int16 int32 int64i8 i16 i32 i64
Unsigneduint8 uint16 uint32 uint64u8 u16 u32 u64

int is shorthand for int32, and uint for uint32. Suffixes attach directly to the literal and are case-insensitive:

val a = 42; val big = 5_000_000i64; val hexv = 0xFF_u8; val bits = 0b1010; print(a, big, hexv, bits);
42 5000000 255 10

Literal rules

FormMeaning
42decimal
0xFF / 0XFFhexadecimal (prefix case-insensitive)
0b1010 / 0B1010binary
0o777 / 0O777octal
5_000_000underscore separators (allowed in any radix)
  • Radix literals can carry suffixes too (0xFF_u8 is legal);
  • The single-letter suffixes L / U / UL do not exist; writing one produces a generic syntax error, and an illegal integer suffix reports MS3137;
  • A bare integer with no suffix resolves to 32-bit int.

Literals bend to fit the target type

With a type annotation in place, a literal automatically adapts to the target type, as long as it fits:

val tiny: int8 = 127; val wide: int64 = 9_000_000_000; val un: uint8 = 200; print(tiny, wide, un);
127 9000000000 200

9_000_000_000 is far beyond 32 bits, but the target int64 can represent it, so the compiler allows it; outside the range, the compiler refuses on the spot. The minus sign is checked together with the literal and refused the same way when out of range:

val tooBig: int8 = 200; // ✗ 200 is outside int8's range val tooLow: int8 = -200; // ✗ -200 is outside int8's range

When the target type annotation feels long, write the suffix on the number instead (the unary minus takes part in the check):

val deep = -100i8; print(deep);
-100
Note

The family also has a byte, 8-bit unsigned, same width as uint8. When you meet one, read it as uint8.

Common functions and formatting

Most of the method surface integers lack lives on the Math module (usable as bare names; the standard library is injected by default):

val n = 42; print(n.ToString("X")); print(Math.Abs(-7), Math.Max(2, 9), Math.Min(2, 9), Math.Sign(-3), Math.Clamp(5, 0, 3));
2A 7 9 2 -1 3
  • ToString() with no argument converts to text; with a format verb (F / N / X / P) it follows the same table as the interpolation {n:X} — see Interpolation;
  • Math.Abs / Max / Min / Sign / Clamp are five common arithmetic functions; to check overflow explicitly use the Math.CheckedAdd family (the default is fixed-width wraparound, unchecked);
  • All of these functions are on the compile-time constant whitelist and may appear directly in a const position.

Notes

  • Overflow and division-by-zero behavior for integer arithmetic is covered on the Operators page;
  • There is no implicit conversion between integers and decimals; see Type Conversions for how to convert;
  • Numeric formatting output (thousands separators, hexadecimal, and so on) is covered under Interpolation.
Last updated on October 11, 2026