Numbers
There are two types of numbers in Gren: integers and floating point.
Integers have the type Int
and represent a whole number:
myInt : IntmyInt = 42
Floating point numbers have the type Float
and are an approximation of a fractional number:
myFloat : FloatmyFloat = 8.67
Gren also has a special number
type that can represent both.
You may have seen it in the repl:
> gren repl---- Gren 0.5.0 -----------------------------------------------------------------Say :help for help and :exit to exit!--------------------------------------------------------------------------------> 123123 : number
You can use this for type signatures where it doesn’t matter if something is an Int or a Float:
double : number -> numberdouble n = n * 2
Math
You can perfrom basic math operations on numbers using the typical operators:
> 1 + 23 : number> 2 - 11 : number> 2 * 36 : number> 6 / 23 : Float
Notice that the division operator returns floats:
> 6 / 41.5 : Float
You can perform integer division with //
:
> 6 // 41 : Int
For exponentation, use ^
:
> 3 ^ 29 : number
For other math operations, see the Math module documentation.