Std.Arithmetic (Cure Standard Library v0.37.2)

View Source

Arithmetic interfaces, split by operation rather than one monolithic Num (spec §2.3): motivated by Std.Measurements (Duration has add/sub/scale but no Duration * Duration — measurements.cure:84-90).

`%` (remainder) is Int-specific and does NOT live on Divisible — Float has no clean total modulo on AtomVM. It is pinned as an Int-only method on its own Integral(t) interface; only Int conforms. Float never implements `%`.

ADDITIVE and DORMANT: operators (+, -, *, /, %) do NOT route through these interfaces yet — build_binop still hardcodes the primitive by operand kind. The methods are callable by their backtick operator name (e.g. `+`(2, 3)). Operator dispatch rewiring is a later task.

Examples

use Std.Arithmetic

`+`(2, 3)                                # => 5
negate(4)                                # => -4
`%`(10, 3)                               # => 1

Summary

Callbacks

Types supporting addition, subtraction, and negation.

Types supporting division.

Types supporting integer remainder. Int-only — Float has no clean total modulo on AtomVM.

Types supporting multiplication.

Callbacks

interface Additive(t)

 interface Additive(t)

Types supporting addition, subtraction, and negation.

interface Divisible(t)

 interface Divisible(t)

Types supporting division.

interface Integral(t)

 interface Integral(t)

Types supporting integer remainder. Int-only — Float has no clean total modulo on AtomVM.

interface Multiplicative(t)

 interface Multiplicative(t)

Types supporting multiplication.

Functions

%(a: t, b: t) -> t

 fn %(a: t, b: t) -> t

a % b.

*(a: t, b: t) -> t

 fn *(a: t, b: t) -> t

a * b.

+(a: t, b: t) -> t

 fn +(a: t, b: t) -> t

a + b.

-(a: t, b: t) -> t

 fn -(a: t, b: t) -> t

a - b.

/(a: t, b: t) -> t

 fn /(a: t, b: t) -> t

a / b.

negate(a: t) -> t

 fn negate(a: t) -> t

-a.