hanki

numeric

stdlib/core/numeric.hk: the Numeric trait, the zero and one identities and the add/mul combining steps, one impl per numeric type.

The bound for generic numeric folds: List.sum / List.product bound <T: Numeric> and reach the identities as T.zero() / T.one() (static-through-bound, the Decode/Arbitrary pattern). The operator traits in ops cannot serve here. An operator impl whose Self is a builtin primitive is rejected (H0573), and a bound on a parameterized trait is still staged (H0569), and the numeric types therefore take this plain trait instead. Each impl's add/mul is the type's native +/*: fixed widths wrap as the operators do, floats remain IEEE, and the lowercase tier's in-band inf/undefined sentinels propagate unchanged.

Numeric

trait Numeric

zero

def zero() -> Self

The additive identity: x.add(T.zero()) == x, and what List.sum returns for the empty list.

int.zero() => 0
i32.zero() => 0i32

one

def one() -> Self

The multiplicative identity: x.mul(T.one()) == x, and what List.product returns for the empty list.

int.one() => 1
f64.one() => 1.0f64

add

def add(self, other: Self) -> Self

The value of self + other, as a bounded-dispatch method.

2.add(3) => 5
2i32.add(3i32) => 5i32

mul

def mul(self, other: Self) -> Self

The value of self * other, as a bounded-dispatch method.

2.mul(3) => 6
2i32.mul(3i32) => 6i32

impl Numeric<int>

zero

def zero() -> Self

This type's 0.

@no-doctest: see the trait method

one

def one() -> Self

This type's 1.

@no-doctest: see the trait method

add

def add(self, other: Self) -> Self

The native + at this type.

@no-doctest: see the trait method

mul

def mul(self, other: Self) -> Self

The native * at this type.

@no-doctest: see the trait method

impl Numeric<i8>

zero

def zero() -> Self

This type's 0.

@no-doctest: see the trait method

one

def one() -> Self

This type's 1.

@no-doctest: see the trait method

add

def add(self, other: Self) -> Self

The native + at this type.

@no-doctest: see the trait method

mul

def mul(self, other: Self) -> Self

The native * at this type.

@no-doctest: see the trait method

impl Numeric<i16>

zero

def zero() -> Self

This type's 0.

@no-doctest: see the trait method

one

def one() -> Self

This type's 1.

@no-doctest: see the trait method

add

def add(self, other: Self) -> Self

The native + at this type.

@no-doctest: see the trait method

mul

def mul(self, other: Self) -> Self

The native * at this type.

@no-doctest: see the trait method

impl Numeric<i32>

zero

def zero() -> Self

This type's 0.

@no-doctest: see the trait method

one

def one() -> Self

This type's 1.

@no-doctest: see the trait method

add

def add(self, other: Self) -> Self

The native + at this type.

@no-doctest: see the trait method

mul

def mul(self, other: Self) -> Self

The native * at this type.

@no-doctest: see the trait method

impl Numeric<i64>

zero

def zero() -> Self

This type's 0.

@no-doctest: see the trait method

one

def one() -> Self

This type's 1.

@no-doctest: see the trait method

add

def add(self, other: Self) -> Self

The native + at this type.

@no-doctest: see the trait method

mul

def mul(self, other: Self) -> Self

The native * at this type.

@no-doctest: see the trait method

impl Numeric<u8>

zero

def zero() -> Self

This type's 0.

@no-doctest: see the trait method

one

def one() -> Self

This type's 1.

@no-doctest: see the trait method

add

def add(self, other: Self) -> Self

The native + at this type.

@no-doctest: see the trait method

mul

def mul(self, other: Self) -> Self

The native * at this type.

@no-doctest: see the trait method

impl Numeric<u16>

zero

def zero() -> Self

This type's 0.

@no-doctest: see the trait method

one

def one() -> Self

This type's 1.

@no-doctest: see the trait method

add

def add(self, other: Self) -> Self

The native + at this type.

@no-doctest: see the trait method

mul

def mul(self, other: Self) -> Self

The native * at this type.

@no-doctest: see the trait method

impl Numeric<u32>

zero

def zero() -> Self

This type's 0.

@no-doctest: see the trait method

one

def one() -> Self

This type's 1.

@no-doctest: see the trait method

add

def add(self, other: Self) -> Self

The native + at this type.

@no-doctest: see the trait method

mul

def mul(self, other: Self) -> Self

The native * at this type.

@no-doctest: see the trait method

impl Numeric<u64>

zero

def zero() -> Self

This type's 0.

@no-doctest: see the trait method

one

def one() -> Self

This type's 1.

@no-doctest: see the trait method

add

def add(self, other: Self) -> Self

The native + at this type.

@no-doctest: see the trait method

mul

def mul(self, other: Self) -> Self

The native * at this type.

@no-doctest: see the trait method

impl Numeric<f32>

zero

def zero() -> Self

This type's 0.

@no-doctest: see the trait method

one

def one() -> Self

This type's 1.

@no-doctest: see the trait method

add

def add(self, other: Self) -> Self

The native + at this type.

@no-doctest: see the trait method

mul

def mul(self, other: Self) -> Self

The native * at this type.

@no-doctest: see the trait method

impl Numeric<f64>

zero

def zero() -> Self

This type's 0.

@no-doctest: see the trait method

one

def one() -> Self

This type's 1.

@no-doctest: see the trait method

add

def add(self, other: Self) -> Self

The native + at this type.

@no-doctest: see the trait method

mul

def mul(self, other: Self) -> Self

The native * at this type.

@no-doctest: see the trait method

impl Numeric<decimal>

zero

def zero() -> Self

This type's 0.

@no-doctest: see the trait method

one

def one() -> Self

This type's 1.

@no-doctest: see the trait method

add

def add(self, other: Self) -> Self

The native + at this type.

@no-doctest: see the trait method

mul

def mul(self, other: Self) -> Self

The native * at this type.

@no-doctest: see the trait method

impl Numeric<rational>

zero

def zero() -> Self

rational has no literal form, and the identities cross in from int.

@no-doctest: see the trait method

one

def one() -> Self

This type's 1.

@no-doctest: see the trait method

add

def add(self, other: Self) -> Self

The native + at this type.

@no-doctest: see the trait method

mul

def mul(self, other: Self) -> Self

The native * at this type.

@no-doctest: see the trait method