Hey John,

I found that there are two exchange functions in pool.cc both of which are
called after in_place_round in amount.cc where I have implemented rounding
currently.  Although the patch is not thoroughly tested but I have added
2-3 common tests for the same. Do you think it can not be the right place
to add this feature?
Please check the patch at
https://gitorious.org/ledger/npo-ledger-cli/raw/680e25846d11fa6e39509dfc4f9b3c6ccb7503f1:rounding/precision.patch

I have inserted extra debug statements in my fork(in debug branch), below
is an example log

D 1000.00 EUR
commodity EUR
  precision 2
  default

2012-01-01 *
   A                        2 AAA @ 10.122 EUR
   A                        1 BBB @ 20.123 EUR
   C

-V bal --debug amount.parse

    0ms  [INFO]  Ledger starting
    2ms  [DEBUG] Rational parsed = 1
    3ms  [DEBUG] amount.cc: parse
    3ms  [DEBUG] amount.cc: parse
    3ms  [DEBUG] Rational parsed = 1
    4ms  [DEBUG] amount.cc: parse
    4ms  [DEBUG] amount.cc: parse
    6ms  [INFO]  Parsing file "test.txt"
    6ms  [DEBUG] Rational parsed = 1000
    6ms  [DEBUG] amount.cc: parse
    7ms  [DEBUG] precision directive called 2
    7ms  [DEBUG] amount.cc: parse
    7ms  [DEBUG] Rational parsed = 5061/500
    7ms  [DEBUG] amount.cc: parse
    8ms  [DEBUG] amount.cc: parse
    8ms  [DEBUG] Rational parsed = 20123/1000
    8ms  [DEBUG] amount.cc: parse
    9ms  [DEBUG] amount.cc:in place round commodity EUR value 20.24
    9ms  [DEBUG] amount.cc:in place round commodity EUR value 20.12
    9ms  [DEBUG] amount.cc:+= value before 20.24
   10ms  [DEBUG] amount.cc:+= value after 40.36 2nd amt 20.12
   10ms  [DEBUG] pool.cc: cost_breakdown_t exchange cost comm EUR
amount comm AAA
   10ms  [DEBUG] amount.cc: is_zero
   10ms  [DEBUG] pool.cc: void exchange
   11ms  [DEBUG] pool.cc: cost_breakdown_t exchange cost comm EUR
amount comm BBB
   11ms  [DEBUG] amount.cc: is_zero
   11ms  [DEBUG] pool.cc: void exchange
   14ms  [INFO]  Read journal file (8ms)
   14ms  [INFO]  Found 1 transactions
   15ms  [DEBUG] amount.cc: parse
   15ms  [DEBUG] amount.cc: parse
   20ms  [DEBUG] post.cc:get_amount wrapper in lookup
   21ms  [DEBUG] post.cc:get_amount
   21ms  [DEBUG] filters.cc:calc_posts
   21ms  [DEBUG] post.cc:get_amount
   21ms  [DEBUG] filters.cc:calc_posts
   21ms  [DEBUG] post.cc:get_amount
   26ms  [DEBUG] account.cc: total
   31ms  [DEBUG] amount.cc:in place round commodity EUR value 20.12
   32ms  [DEBUG] amount.cc:in place round commodity EUR value 20.24
   32ms  [DEBUG] balance.cc: amount added, value before 20.12
   32ms  [DEBUG] amount.cc:+= value before 20.12
   33ms  [DEBUG] amount.cc:+= value after 40.36 2nd amt 20.24
   33ms  [DEBUG] balance.cc: amount added, value after 40.36
   33ms  [DEBUG] amount.cc: is_zero
   34ms  [DEBUG] account.cc: total
   34ms  [DEBUG] amount.cc: is_zero
   34ms  [DEBUG] format.cc:real_calc formatting
   36ms  [DEBUG] amount.cc:+= value before 20
   36ms  [DEBUG] amount.cc:+= value after 20 2nd amt 0
   37ms  [DEBUG] amount.cc:in place round commodity EUR value 20.12
   37ms  [DEBUG] amount.cc:in place round commodity EUR value 20.24
   37ms  [DEBUG] balance.cc: amount added, value before 20.12
   38ms  [DEBUG] amount.cc:+= value before 20.12
   38ms  [DEBUG] amount.cc:+= value after 40.36 2nd amt 20.24
   38ms  [DEBUG] balance.cc: amount added, value after 40.36
   38ms  [DEBUG] amount.cc: is_zero
           40.36 EUR  A
   40ms  [DEBUG] format.cc:real_calc formatting
   41ms  [DEBUG] amount.cc:+= value before 20
   41ms  [DEBUG] amount.cc:+= value after 20 2nd amt 0
   41ms  [DEBUG] amount.cc: is_zero
   42ms  [DEBUG] amount.cc: is_zero
          -40.36 EUR  C
   43ms  [DEBUG] format.cc:real_calc formatting
--------------------
   43ms  [DEBUG] format.cc:real_calc formatting
   44ms  [DEBUG] amount.cc:+= value before 20
   45ms  [DEBUG] amount.cc:+= value after 20 2nd amt 0
   45ms  [DEBUG] amount.cc:in place round commodity EUR value 20.12
   46ms  [DEBUG] balance.cc: amount added, value before -40.36
   46ms  [DEBUG] amount.cc:+= value before -40.36
   46ms  [DEBUG] amount.cc:+= value after -20.24 2nd amt 20.12
   47ms  [DEBUG] balance.cc: amount added, value after -20.24
   47ms  [DEBUG] amount.cc:in place round commodity EUR value 20.24
   47ms  [DEBUG] balance.cc: amount added, value before -20.24
   48ms  [DEBUG] amount.cc:+= value before -20.24
   48ms  [DEBUG] amount.cc:+= value after 0 2nd amt 20.24
   48ms  [DEBUG] balance.cc: amount added, value after 0
                   0
   49ms  [INFO]  Finished executing command (29ms)
   49ms  [INFO]  Ledger ended




On Tue, Jul 1, 2014 at 2:23 AM, John Wiegley <[email protected]> wrote:

> >>>>> Martin Michlmayr <[email protected]> writes:
>
> > Now that I think about it some more, aren't all rounding problems we've
> > encountered so far related to valuing one commodity in terms of another?
>  If
> > so, you'd need to find where this is done and implement rounding there.
>
> That would be commodity_pool_t::exchange, in pool.cc, if that is the case.
>
> John
>
> --
>
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "Ledger" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ledger-cli/xGgpdJCGCq4/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 

--- 
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.

Reply via email to