allocate
Splits a total into weighted parts while preserving the quantized target total exactly.
API Reference
Signature
Parameters
Returns
Returns an ArithInstance[] with the same length as weights. The sum of all returned parts equals the quantized target total.
Throws
- Throws if
weightsis not a non-empty array. - Throws if
totalisNaN,Infinity, or-Infinity. - Throws if any weight is non-finite or negative.
- Throws if all weights are zero.
- Throws if
decimalPlaces,step, orroundingModeis invalid. - Throws if both
decimalPlacesandstepare provided.
Agent Contract
Agent Notes
- Use
Arith.allocate(total, weights, options?)for deterministic amount, fee, holding, or unit distribution. - Do not generate an instance method such as
Arith.from(total).allocate(...). - Use
decimalPlacesfor decimal-place money rules andstepfor lot-size or tick-size rules. - Do not pass both
decimalPlacesandstep. roundingModeonly quantizes the target total; remainder distribution always uses stable largest remainder order.- Prefer string inputs for exact decimal totals, weights, and steps.