Mélodium have multiple core data types, shared across four main categories, plus
- unsigned integers
- signed integers
- floating-point numbers
- textual data
All those types are described across their respective section. Each type has been selected because it meets a very specific purpose.
|Unsigned integers||Signed integers||Floating-point numbers||Text||Logic|
|Any 8-bits data||8 bits / 1 byte|
byte is basically the most atomic unit of data manipulable through Mélodium.
It represents any 8-bits data, without more assumption on what it could be.
|8 bits / 1 byte|
bool is a boolean value that can be either set to
Conversion treatments are available for
bools to be turned into bytes, numbers, or any kind of value.
|None||0 bit / 0 byte|
void data type does not hold any value, it just indicates that something is existing.
It is used through connections to transmit triggers or streaming indicators.
|0 to 2⁸-1 (255)||8 bits / 1 byte|
|0 to 2¹⁶-1 (65,535)||16 bits / 2 bytes|
|0 to 2³²-1 (4,294,967,295)||32 bits / 4 bytes|
|0 to 2⁶⁴-1 ( > 18×10¹⁸)||64 bits / 8 bytes|
|0 to 2¹²⁸-1 ( > 34×10³⁷)||128 bits / 16 bytes|
|-2⁷ (-128) to 2⁷-1 (127)||8 bits / 1 byte|
|-2¹⁵ (-32,768) to 2¹⁵-1 (32,767)||16 bits / 2 bytes|
|-2³¹ (-2,147,483,648) to 2³¹-1 (2,147,483,647)||32 bits / 4 bytes|
|-2⁶³ ( ≈ -9×10¹⁵) to 2⁶³-1 ( ≈ 9×10¹⁵)||64 bits / 8 bytes|
|-2¹²⁷ ( ≈ -34×10³⁷) to 2¹²⁷-1 ( ≈ 34×10³⁷)||128 bits / 16 bytes|
|See description||32 bits / 4 bytes|
|See description||64 bits / 8 bytes|
Floating-point numbers are defined in IEEE 754-2008. They can mostly be considered as decimal numbers, for a deeper explanation, please refers to the Single-precision floating-point format (for
f32) and Double-precision floating-point format (for
f64) articles on Wikipedia.
They can store positive or negative values, but also be in one of those three states:
- positive infinity, can be result of something like
- negative infinity, can be result of something like
- not a number, can be result of a square root of negative number (aka. complex number).
|Any valid Unicode scalar value||32 bits / 4 bytes|
|Any valid UTF-8 text||Variable|
All textual information is represented as Unicode. A
char uses 4 bytes to store any Unicode scalar value, as defined in Unicode Standard. Unlike many other programming languages, Mélodium does not assume a char and a byte (nor combination of bytes) to be equivalent at all, for many reasons such as:
- a byte only have 256 values, while all human languages combined have much more "letters";
- a letter in Unicode Text Format can be up to 4 bytes;
- lot of values are illegal according to Unicode;
- Unicode standard provide a strong universality of what textual data can be represented;
- making data types reliable, each one having its own purpose, then
charguarantees valid text data while
byteonly assume it is data.
string data type can represent any UTF-8 text and its size depends on the length of the text. Interestingly,
strings are not a combination of
chars, but real UTF-8 strings. Taking the text
Mélodium and putting it as vector of chars, 32 bytes (8 chars × 4 bytes) are used, but as string only 9 bytes. This technical subtility is transparent for users and conversion treatments are provided if needed.
Mélodium can handle many encodings through its encoders and decoders, taking and providing byte streams.