Integers in Gera specifically are signed 64-bit integers, with the smallest possible value being -9223372036854775808 and the largest possible value being 9223372036854775807. Simply write the value to create an integer value. Integer arithmetic is defined to be wrap around on overflow.
proc main() {
val a = 5
val b = 10
}
Floats in Gera specifically are double-precision 64-bit binary format (IEEE 754) floats. To create a float value, write the number, making sure to include the decimal point. Number literals without decimal points are interpreted as integers.
proc main() {
val a = 5.0
val b = 3.14
val c = 0.345
}
The following operations can be used with both integers and floats (although they may not both be involved in the same operation):
- -x negates x and results in the result.
- a + b results in the sum of a and b.
- a - b results in b subtracted from a.
- a * b results in the product of a and b.
- a / b results in a divided by b.
- a % b results in the remainder of a divided by b. Note that the result will have the same sign as a.
- a < b results in true if a is less than b and otherwise results in false.
- a > b results in true if a is greater than b and otherwise results in false.
- a <= b results in true if a is less than or equal to b and otherwise results in false.
- a >= b results in true if a is greater than or equal to b and otherwise results in false.
- a == b results in true if a and b have the same value.
- a != b results in true if a and b have different values.
use std::io::println
proc main() {
val a = 5
val b = 3
val c = a % b
val d = c + 5
println(d) // prints '7'
println(d < a) // prints 'false'
}
Numbers can be converted to integers and floats using the built-in as_int- and as_flt-procedures. Note that as_int truncates floats, rounding them towards zero.
proc main() {
val pi = 3.1415
println(as_int(pi)) // prints '3'
println(as_flt(25) + 0.25) // prints '25.25'
}