Skip to content

Numeric

There are 3 numeric types in NC: int, uint, and float.

Integer

Warning

If a value exceeds the range of int or uint, the program will panic and crash.

Int

The int type is a 64-bit signed integer type.

You can declare ints by simply writing a number without a decimal point, or converting from a different type by using the int() function:

int my_num = 1
int my_num = int(1)

Uint

The uint type is a 64-bit unsigned integer. A uint can be declared similarly to an int, and the uint() function can be called to convert from a different type:

uint my_num = 1 // cannot be negative
uint my_num = 1u // can also use the `u` suffix
uint my_num = uint(1) // equivalent to the above expression

If any of the integer conversion functions are used on a float, then only the integer part will be returned. So, for example, int(2.5) will become 2.

Hexadecimal and Octal

Hexadecimal numbers need to be prefixed with 0x, for example, 0xFF. The part after the 0x is case-insensitive.

Octal numbers need to be prefixed with 0o, for example, 0o777.

Float

The float type is a 64-bit floating point number, following the IEEE 754 standard. It can be declared by writing a number with a decimal point, or using the float() function to convert it from another type.

// all of these have the same output
float my_float = 1.0
float my_float = float(1) // fn float(int n) -> float
float my_float = float(1u) // fn float(uint n) -> float