cairo-numeric-types
Installation
SKILL.md
Cairo Numeric Types
Overview
Guide implementing production-quality custom numeric types (fixed-point, big integers, signed integers) in Cairo following Ekubo-style patterns.
Quick Use
- Read
references/numeric-types.mdbefore answering. - Study Ekubo's i129 - the gold standard for signed integers in Cairo.
- Use constructor functions to enforce invariants (e.g., no negative zero).
- Provide both checked (returns Option) and unchecked (panics) API variants.
- Implement standard traits: PartialEq, PartialOrd, Add, Sub, Mul, Neg, Zero, One.
Response Checklist
Invariant Enforcement
- Use a private constructor function that enforces invariants (Ekubo i129 pattern).
- Example:
fn i256_new(mag: U256, neg: bool) -> I256 { I256 { mag, neg: neg && !u256_is_zero(mag) } } - Never allow invalid states like negative zero.