Skip to content

Negative zero not treated the same as positive 0 #2531

@alerque

Description

@alerque

I'm not sure this should be considered a bug, but I was playing around with how something should be recorded and bumped up against an odd bug creating balanced transactions. The deal is when working with costs, negating credits vs. debits works differently. I really only bumped into this because Ledger CLI handles this differently and I was exporting to there and it choked over my inputs. In tweaking the inputs to the way it expected (all costs being positive) I discovered I couldn't negate a zero in hledger. I can multiply by zero, but not negative zero.

Consider this ledger which balances in HLedger:

2000-01-01 Opening balance
  Assets:Cash                                           $10.00
  Equity:Balances

2000-01-01 Vendor A  ; I pay for something for somebody else
  Liabilities:Reimbursable:PersonA                      $10.00
  Assets:Cash                                          $-10.00

2000-01-01 Person A  ; They pay me back at an over generous exchange rate
  Assets:Cash                                          ₺450,00
  Liabilities:Reimbursable:PersonA                     $-10.00 @ ₺44,00  ; market conversion rate
  Liabilities:Reimbursable:PersonA                        0 @@ ₺-10,00  ; "call it even between frinds"

The solution in Ledger CLI would be to keep the cost positive but make sure the posting is a debit not a credit:

2000-01-01 Opening balance
  Assets:Cash                                           $10.00
  Equity:Balances

2000-01-01 Vendor A  ; I pay for something for somebody else
  Liabilities:Reimbursable:PersonA                      $10.00
  Assets:Cash                                          $-10.00

2000-01-01 Person A  ; They pay me back at an over generous exchange rate
  Assets:Cash                                          ₺450,00
  Liabilities:Reimbursable:PersonA                     $-10.00 @ ₺44,00  ; market conversion rate
  Liabilities:Reimbursable:PersonA                       -0 @@ ₺10,00  ; "call it even between frinds"

HLedger on the other hand is not too fond of that:

9 | 2000-01-01 Person A  ; They pay me back at an over generous exchange rate
  |     Assets:Cash                                  ₺450,00
  |     Liabilities:Reimbursable:PersonA    $-10.00 @ ₺44,00  ; market conversion rate
  |     Liabilities:Reimbursable:PersonA         0 @@ ₺10,00  ; "call it even between frinds"

This multi-commodity transaction is unbalanced.
The real postings' sum should be 0 but is: ₺20,00
Consider adjusting this entry's amounts, adding missing postings,
or recording conversion price(s) with @, @@ or equity postings.

I understand that mathematically negative zero is not particularly meaningful, but for that matter neither is 0 × <anything>. In math that would evaluate to zero no matter what. In a posting right now that's actually a way to fudge currency conversion costs using a throw-away conversion commodity rather than a throw-away conversion account.

I was taking this approach because I wanted to use my prices database to sanity check currency conversion postings. If I stuff these random amounts coming in and out of an Equity:Conversion account I kind of throw off that math. There might be a better way to handle this, but given that 0 × 𝓧 is being evaluated to 𝓧 and 0 × -𝓧 is being evaluated to -𝓧 I was surprised to find -1 × 𝓧 was evaluated to 𝓧. I expected -𝓧.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-WISHSome kind of improvement request or proposal.journalThe journal file format, and its features.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions