Add built-in numeric math operations. Currently Vera has arithmetic operators (+, -, *, /, %) and comparison operators but no math utility functions.
Proposed functions
Integer math
abs(@Int -> @Nat) — absolute value
min(@Int, @Int -> @Int) — minimum of two values
max(@Int, @Int -> @Int) — maximum of two values
Float math
floor(@Float64 -> @Int) — floor to integer
ceil(@Float64 -> @Int) — ceiling to integer
round(@Float64 -> @Int) — round to nearest integer
sqrt(@Float64 -> @Float64) — square root
pow(@Float64, @Float64 -> @Float64) — exponentiation
Implementation notes
All are pure functions. Most map directly to WASM instructions:
abs: compare + negate
min/max: i64.lt_s + select
floor/ceil/round: f64.floor/f64.ceil/f64.nearest + i64.trunc_f64_s
sqrt: f64.sqrt
pow: requires a loop or import (no native WASM instruction)
These are quick wins — most are 5-10 lines of WAT each.
Dependencies
Add built-in numeric math operations. Currently Vera has arithmetic operators (+, -, *, /, %) and comparison operators but no math utility functions.
Proposed functions
Integer math
abs(@Int -> @Nat)— absolute valuemin(@Int, @Int -> @Int)— minimum of two valuesmax(@Int, @Int -> @Int)— maximum of two valuesFloat math
floor(@Float64 -> @Int)— floor to integerceil(@Float64 -> @Int)— ceiling to integerround(@Float64 -> @Int)— round to nearest integersqrt(@Float64 -> @Float64)— square rootpow(@Float64, @Float64 -> @Float64)— exponentiationImplementation notes
All are pure functions. Most map directly to WASM instructions:
abs: compare + negatemin/max:i64.lt_s+selectfloor/ceil/round:f64.floor/f64.ceil/f64.nearest+i64.trunc_f64_ssqrt:f64.sqrtpow: requires a loop or import (no native WASM instruction)These are quick wins — most are 5-10 lines of WAT each.
Dependencies