In Kuin, you use the int type for integers and the float type for decimals. They can perform basic arithmetic operations such as the four arithmetic operations (Figure 1-1).
Use the symbols "+" for addition, "-" for subtraction, "*" for multiplication, "/" for division, "%" for remainder of division, and "^" for power. You can write Kuin expressions in the same way as mathematical expressions, with multiplication being done before addition and parentheses changing the order of calculations.
The "/" operation on the int type will be truncated to the decimal point after the calculation.
When you write a number directly on the source code, if you write something like "5" or "-3", the number will be of type int, and if you write something with "." like "5.0" or "-3.0", the number will be of type float.
To compare the size of a value to a number of type int or float, use the comparison operators (Figure 1-2).
Each comparison operator is roughly equivalent to a mathematical symbol. The "<=" corresponds to "", ">=" corresponds to "", and "<>" corresponds to "".
However, the float type is subject to calculation errors, so even if the comparison matches mathematically, comparing with "=" may return false. Therefore, the lib@same function can be used to make comparisons with some allowance for calculation errors (Figure 1-3).
For numbers of type int or float, use the .abs method for absolute values to make a negative number positive, and use the .sign method to get 1 if the sign is positive, -1 if negative, or 0 if zero (Figure 1-5).
To perform operations in bit units, use the bit8, bit16, bit32, and bit64 types (Figure 2-1).
The bit8, bit16, bit32, and bit64 types can handle sizes of 8, 16, 32, and 64 bits, respectively, and cannot handle negative values.
When writing bit8, bit16, bit32, and bit64 numbers directly in the source code, they are represented by adding the suffixes "b8", "b16", "b32", and "b64" after the number notation in the int type, respectively.
These types can perform bitwise operations such as and, or, not, and xor (Figure 2-2).
To handle characters in Kuin, the char type is used. When writing characters directly in the source code, enclose them in "'" to represent them.(Figure 3-1)。
The char type is internally an integer between 0x0000 and 0xFFFF, and characters are stored in UTF-16 character code. By using the "$" operator to convert to the int type, you can operate directly in character code.
To represent special characters such as line feeds in the source code, use a combination of the "\" character and a single character. For example, a newline character is written as "'\n'" (Figure 3-2).
Use the bool type when you want to handle logical values, such as when expressing conditions such as "if ...". The bool type has only two values: "true" for true, and "false" for false (Figure 4-1).
In Kuin, the symbol "|" is used for logical disjunction, which corresponds to "... or ...", and the symbol "&" is used for logical conjunction, which corresponds to "... and ...". You can also write "conditional expression ?(value when true, value when false)", you can also get the value according to the logical value (Figure 4-2).
The results of the "|" and "&" operators are shown in Table 4-1.