Numeric Constants
In the Fuzion base module, all numeric types inherit from
type numeric. This includes basic types
like i32, f64, but also composed types
like num.fraction or num.complex.
To simplify numeric operations in code that
is type parametric for any numeric type,
integer constants can be used as values of a parametric type that is
constrained by numeric. The followiwng example shows how this is
used to create the constant 23 representation for different
numeric types.
Internally, numeric constants are just syntax sugar for a call
to from_u32 on the numeric type parameter using the constant as
an argument, so the example above is equivalent to
This works not only for numeric types from the Fuzion base module, but as well
for user defined numeric types. The following code defines
an integer type for modulo 7 arithmetic. It inherits
from integer, which itself inherits from numeric: