Skip to content
Docs
Types
Numerics

Numerics

Int and Float types are the two numeric types in Risor. They correspond to boxed int64 and float64 values in Go. Risor automatically converts Ints to Floats in mixed type operations.

The standard set of numeric operators are available when working with these types.

OperationResult
x + ysum of x and y
x - ydifference of x and y
x * yproduct of x and y
-xnegation of x
x ** yx to the power of y
x += yadd y to x
x -= ysubtract y from x
x *= ymultiply x by y
x /= ydivide x by y
>>> x := 2
2
>>> y := 3
3
>>> x * y
6
>>> x + y
5
>>> type(x + y)
"int"
>>> type(x + float(y))
"float"

Many math functions are also available in the Risor math module.

Related Built-ins

float(x)

Converts a String or Int object to a Float. An error is generated if the operation fails.

>>> float("4.4")
4.4

int(x)

Converts a String or Float to an Int. An error is generated if the operation fails.

>>> int(4.4)
4
>>> int("123")
123