package
0.0.0-20250213232608-c453f8b35c75
Repository: https://github.com/stellar/go.git
Documentation: pkg.go.dev
# Functions
ConvertToBuyingUnits uses special rounding logic to multiply the amount by the price and returns (buyingUnits, sellingUnits) that can be taken from the offer
offerSellingBound = (offer.price.n > offer.price.d) ? offer.amount : ceil(floor(offer.amount * offer.price) / offer.price) pathPaymentAmountBought = min(offerSellingBound, pathPaymentBuyingBound) pathPaymentAmountSold = ceil(pathPaymentAmountBought * offer.price)
offer.amount = amount selling offerSellingBound = roundingCorrectedOffer pathPaymentBuyingBound = needed pathPaymentAmountBought = what we are consuming from offer pathPaymentAmountSold = amount we are giving to the buyer
Sell units = pathPaymentAmountSold and buy units = pathPaymentAmountBought
this is how we do floor and ceiling in stellar-core: https://github.com/stellar/stellar-core/blob/9af27ef4e20b66f38ab148d52ba7904e74fe502f/src/util/types.cpp#L201.
MulFractionRoundDown sets x = (x * n) / d, which is a round-down operation see https://github.com/stellar/stellar-core/blob/9af27ef4e20b66f38ab148d52ba7904e74fe502f/src/util/types.cpp#L201.
MustParse is like Parse except that it panics on errors.
Parse calculates and returns the best rational approximation of the given real number price while still keeping both the numerator and the denominator of the resulting value within the precision limits of a 32-bit signed integer..
StringFromFloat64 will format a float64 to decimal representation with 7 digits after the decimal point.
# Variables
ErrDivisionByZero is returned when a price operation would result in a division by 0.
ErrOverflow is returned when a price operation would result in an integer overflow.