A fixed point math library in 64.64 representation built for Cairo 1.0 & Starknet. Successor to influenceth/cairo-math-64x61
Cubit is currently a WORK IN PROGRESS and should not be used in production (yet). Contributions are welcomed.
Cubit was built with auditless/cairo-template
, reference its installation guide to install dependencies.
A signed 64.64-bit fixed point number is a fraction in which the numerator is a signed 128-bit integer and the denominator is 2^64. Since the denominator stays the same there is no need to store it (as in a floating point value).
Can represent values in the range of -2^64 to 2^64 with precision to 1e-20.
cubit::core
includes the following implementations for the Fixed
type:
FixedTrait::from_felt
- creates aFixed
type from a pre-scaledfelt
FixedTrait::from_int
- creates and scales afelt
into aFixed
typeInto
(fixed.into()
) - converts theFixed
value into afelt
Add
(+
)AddEq
(+=
)Sub
(-
)SubEq
(-=
)Mul
(*
)MulEq
(*=
)Div
(/
)DivEq
(/=
)PartialEq
(==
,!=
)PartialOrd
(>
,>=
,<
,<=
)fixed.ceil
fixed.exp
fixed.floor
fixed.ln
fixed.log2
fixed.log10
fixed.pow
fixed.round
fixed.sqrt