Skip to content

Add math extension functions - #327

Open
rayokota wants to merge 1 commit into
bufbuild:mainfrom
rayokota:math-ext
Open

Add math extension functions#327
rayokota wants to merge 1 commit into
bufbuild:mainfrom
rayokota:math-ext

Conversation

@rayokota

@rayokota rayokota commented Aug 16, 2026

Copy link
Copy Markdown

What

Adds a math extension exposing CEL's namespaced numeric functions, enabled the
same way as the existing strings extension:

import { math } from "@bufbuild/cel/ext";                                                                                                                                         
                                                                                                                                                                                  
run(`math.abs(-4) == 4`, {}, { funcs: math }); // true     

Functions: abs, sign, sqrt, ceil, floor, round, trunc, isInf,
isNaN, isFinite, bitAnd, bitOr, bitXor, bitNot, bitShiftLeft,
bitShiftRight. Ported from cel-go's ext/math.go

Not included: math.greatest / math.least

These are variadic receiver macros, which require parser-macro support that
extensions don't have today. They're intentionally left out and their conformance
cases remain skipped. I'm happy to follow up with the macro mechanism if there's
interest in a design discussion.

Notes

  • Additive only — no changes to any exported API shape. math is a CelFunc[], matching strings.
  • Semantics match cel-go: round is half-away-from-zero, right shift is logical,
    abs(minInt64) errors, shifts ≥ 64 yield 0, negative shifts error.
  • The conformance suite's non-macro math_ext cases are un-skipped (only
    greatest/least remain skipped).

Testing

  • Full suite green; the newly enabled math_ext conformance cases pass.
  • attw clean for @bufbuild/cel and @bufbuild/cel/ext.
  • README updated with a math example.

@CLAassistant

CLAassistant commented Aug 16, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants