diff options
author | Max Nikulin <manikulin@gmail.com> | 2024-07-08 17:17:30 +0700 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2024-08-05 08:35:14 -0700 |
commit | e6dae78c033ea970a459b1a0ccc2f1310d1bff96 (patch) | |
tree | 510dc67c111f786f3a2ecdb861b4602c73a04e64 /doc/ledger3.texi | |
parent | 064012a0d8c18aac253de79154175400fe7ad9cc (diff) | |
download | fork-ledger-e6dae78c033ea970a459b1a0ccc2f1310d1bff96.tar.gz fork-ledger-e6dae78c033ea970a459b1a0ccc2f1310d1bff96.tar.bz2 fork-ledger-e6dae78c033ea970a459b1a0ccc2f1310d1bff96.zip |
Fix denominator of roundto result
Multiprecision rational created from a double value may have large power
of 2 denominator since fractional decimal numbers can not be represented
as binary floating point numbers. It leads to failed assertion when
result is compared to a value converted directly from strings.
Use integer multiprecision arithmetics to round numbers to ensure
proper denominator. Inspired by python gmpy2 package
<https://github.com/aleaxit/gmpy/blob/3e4564ae9d/src/gmpy2_mpq_misc.c#L315>
The change makes `roundto` symmetric for positive/negative arguments.
Halves are rounded to nearest even. Rounded away from zero are discussed
in #1663 and it may be achieved with minimal modification.
- See #2329
- Closes #1983
Diffstat (limited to 'doc/ledger3.texi')
-rw-r--r-- | doc/ledger3.texi | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/doc/ledger3.texi b/doc/ledger3.texi index e9cadefb..02680caa 100644 --- a/doc/ledger3.texi +++ b/doc/ledger3.texi @@ -8660,7 +8660,7 @@ $ ledger -f expr.dat --format "%(account) %(roundto(amount, 1))\n" reg @end smallexample @smallexample @c output:B4DFB9F Assets:Cash ¤ -123,40 -Expenses:Office Supplies ¤ 123,50 +Expenses:Office Supplies ¤ 123,40 @end smallexample @end defun |