numeric types
About integer and floating-point data.
Description
In Nelson you can specify the data type of a numeric literal by using a suffix or a type specifier.
Here are some common suffixes for specifying the data type of numeric literals:
f32
single (float single precision)
f64
double (float double precision)
i8
int8 (8-bit signed integer)
i16
int16 (16-bit signed integer)
i32
int32 (32-bit signed integer)
i64
int64 (64-bit signed integer)
u8
uint8 (8-bit unsigned integer)
u16
uint16 (16-bit unsigned integer)
u32
uint32 (32-bit unsigned integer)
u64
uint64 (64-bit unsigned integer)
i64: To specify a 64-bit signed integer, you can use the i64 suffix. example: A = 42i64
f32: To specify a 32-bit floating-point number (single precision), you can use the f64 suffix. example: 3.14f32
These suffixes help the Nelson infer the correct data type for the literal.
Nelson automatically infer data type by default as double and you don't need to specify this suffixe explicitly. example: A = 3.14
Unless you have specific requirements or need to disambiguate between data types, you often don't need to explicitly specify the type of numeric literals.
But when you create a numeric array of large integers in Nelson, especially when they exceed the maximum precision representable by double (larger than flintmax), Nelson initially stores these values as double-precision floating-point numbers by default.
Examples
explicit single number
implicit-explicit double number
values exceed maximum precision representable by double
See also
double, single, int8, int16, int32, int64, uint8, uint16, uint32, uint64.
History
1.0.0
initial version
Author
Allan CORNET
Last updated