On Tue, 30 Jan 2018 at 22:10 Clément Pit-Claudel <[email protected]> wrote:
> > > These numbers will be converted to a rational that looks correct when > > displayed but does not equal the true number. > > Of course, this makes sense. I wonder why "ledger eval --unround > '(roundto($0.31 / 2, 2))'" doesn't show this imprecision. (Shouldn't it?) > > I expected round to work differently; something like this maybe? > > round (a / b, n) > // = round (a / b * 10^n, 0) / 10 ^ n > // = intpart(a * 10^n / b) / 10 ^ n > = (a * 10^n - (a * 10^n mod b)) / 10^n > This is basically what the current implementation does (except that a/b is computed before the call to round). The real issue is that it round-trips to double when doing the rounding. To fix the issue I think the rounding must be done entirely with arbitrary precision numbers. Unfortunately I'm not quite familiar with the GMP library [0] ledger uses for arbitrary precision numbers, so I'm not sure how to do this. [0] https://gmplib.org/manual/ -- --- You received this message because you are subscribed to the Google Groups "Ledger" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
