Repository navigation
Square roots, and a rounding strategy on the operations that round.
Added
Dec::sqrt,Dec::checked_sqrtandDec::sqrt_approx.sqrtrounds half
away from zero atDec::SCALEand is the one operation here that cannot
overflow: the largest root the range holds is about1.3e10, so a negative
value and NaN are its only failures, which is whatchecked_sqrtreports as
None.sqrt_approxgoes throughf64for about three times the speed,
accurate to the double's sixteen significant digits rather than to the last
place; take it where a root feeds a comparison, not where two of them are
tested equal.RoundingStrategy, taken byDec::round_dp_withand
Dec::round_to_step_with:MidpointAwayFromZero,MidpointNearestEven,
ToZero,AwayFromZero,ToNegativeInfinityandToPositiveInfinity. Pass
one where the direction is the exchange's rather than yours:ToZerofor a
quantity filter, the infinity pair for a bid or ask pinned to a tick,
MidpointNearestEvenwhere many rounded values are summed. It derives
DefaultasMidpointAwayFromZeroand serialises under theserdefeature,
so a per-instrument policy stores and restores with the instrument.
Changed
round_dpandround_to_stepare unchanged, and are now defined as the
MidpointAwayFromZerocase of their_withcounterparts.floor,ceil
andtruncare thedp0 cases of the three directed strategies, and say so
in their docs.- The
arithmeticbenchmark is nowdecand carries the roots alongside the
arithmetic, socargo bench --bench arithmeticiscargo bench --bench dec.
make benchis unchanged.docs/bench-data.jsonis re-measured, and the
site's front page hands off to aDecpage for the per-operation numbers. - The readme says who writes this crate: every line generated by an AI agent
under the review of high frequency trading practitioners, and what a
contribution has to clear before it lands.