Skip to content

Numeric math builtins #199

Description

@aallan

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

  • None

Metadata

Metadata

Assignees

No one assigned

    Labels

    codegenCode generation backendenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions