Integer are discrete numbers including negative numbers. In Computer Science, integer namber have a range limitation and does not support infinity. The range depend on number of bytes used for representation of the number. In all programming languages, the number of bytes is fixed.
proc integer_demo: int = let a = 11 b = 4 echo "a + b = ", a + b echo "a - b = ", a - b echo "a * b = ", a * b echo "a / b = ", a / b echo "a div b = ", a div b echo "a mod b = ", a mod b return 0
a + b = 15 a - b = 7 a * b = 44 a / b = 2.75 a div b = 2 a mod b = 3
Note: Integer literals are simple including digits and sign like in example above. The most intresting is the division that can produce a float result, unlike other languages.
Real numbers can't be represented in Computer Science. A good aproximation of Real Numbers is implemented as Float Numbers. These are natively supported by computer procesors and standard for most programming languages.
let c = 6.75 d = 2.25 echo "c + d = ", c + d echo "c - d = ", c - d echo "c * d = ", c * d echo "c / d = ", c / d
c + d = 9.0 c - d = 4.5 c * d = 15.1875 c / d = 3.0
Notes: Integer literal 9 is not the same as literal 9.0 that is float. In Nim you can't use integers and float in the same expression. You must make explicit conversion before computing an expression.
// code example to be replaced
Read next: Page Name