Numeric Operations
All the numeric types (i.e., core.Byte, core.Int, core.Nat,
core.Long, core.Word, core.Float, and core.Double)
provide the standard arithmetic operators (i.e., +, -, *, /). All operators can be combined
with = to form += and so on. Integer types additionally provide prefix and postfix operators for
increment and decrement (i.e. x++ and ++x). The unsigned types also provide bitwise operators
(i.e. &, |, ^, ~).
It is possible to convert between the types using member functions in the standard types. For example, converting an integer to a float can be done as follows:
Int x = 10; Float y = x.float;
The system also provides the following operations in addition to regular operators:
-
min(x, y),max(x, y)- minimum and maximum values -
sqrt(x)- square root of floating point types -
pow(base, exp)- exponential of floating point types -
exp(exp)- the natural exponential of floating point types -
log(v)- the natural logarithm of floating point types -
abs(x)- absolute value -
clamp(value, min, max)- limit a value to a range
Finally, the types provides the following static operations:
-
min(e.g.Int:min) - provide the lowest representable value. -
max(e.g.Long:max) - provide the highest representable value.
Note: Floating point types use min and max to represent the largest and smallest positive value
that can be represented (i.e. min returns a positive but very small number). Floating point types
also provide infinity to get the positive infinity value, as well as ceil and floor to round
up and down respectively.
Complex numbers
The system also provides the class core.Complex, which represents complex numbers (using
core.Float). It behaves much like built-in numeric types, and has the following members:
-
core.Float realReal part of the number.
-
core.Float imagImaginary part of the number.
-
core.Complex +(core.Complex& o)Addition.
-
core.Complex -(core.Complex& o)Subtraction.
-
core.Complex -()Negation.
-
core.Complex *(core.Complex& o)Multiplication.
-
core.Complex /(core.Complex& o)Division.
-
core.Float length()Length.
-
core.Complex conjugate()Conjugate.
-
core.Complex exp()Exponentiation using e.
-
core.Complex log()Natural logarithm.
