-
Notifications
You must be signed in to change notification settings - Fork 508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong calculation due to incorrect expression parsing with subtraction #2001
Comments
I don't know why, but you are absolutely right.
Debug:
|
|
Even simpler testcase:
debug:
|
These all work fine:
|
This was actually reported before, see #1809 |
none of those have a commodity assigned. Does subtraction work if it does
have a commodity assigned?
On Mon, Feb 8, 2021 at 02:22 Martin Michlmayr ***@***.***> wrote:
These all work fine:
2020/01/01 works
Assets:Cash (3*1)
Equity
2020/01/01 works
Assets:Cash (3/1)
Equity
2020/01/01 works
Assets:Cash (3+1)
Equity
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2001 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGWWLCGBZBBXAL32J22ML3S56UO3ANCNFSM4XIRMLSQ>
.
--
Craig, Corona De Tucson, AZ
[image: missile_flyout]
enderw88.wordpress.com
|
yes, but imho that's not the point since a) value expressions support math, b) the original example had a commodity somewhere in the expression, and c) ledger doesn't require commodities. |
Negative signs?
…On Mon, Feb 8, 2021 at 6:25 AM dslad ***@***.***> wrote:
The problem seems to be in the *parse_quantity* function in amount.cc
<https://github.com/ledger/ledger/blob/master/src/amount.cc>.
Compiling with the offending "*|| c == '-'*" removed seems to function
properly on the trivial examples.
I can't think why hyphens should be allowed in quantities (unlike of
course . and , ) ... but there may be a reason?
namespace {
void parse_quantity(std::istream& in, string& value)
{
char buf[256];
char c = peek_next_nonws(in);
READ_INTO(in, buf, 255, c,
std::isdigit(c) || c == '-' || c == '.' || c == ',');
string::size_type len = std::strlen(buf);
while (len > 0 && ! std::isdigit(buf[len - 1])) {
buf[--len] = '\0';
in.unget();
}
value = buf;
}
}
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2001 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGWWLDDQHXX46CVA5GCJELS57Q5VANCNFSM4XIRMLSQ>
.
--
Craig, Corona De Tucson, AZ
[image: missile_flyout]
enderw88.wordpress.com
|
:) Seems to still recognise minus sign at the beginning of a quantity - it's ones in the middle that were causing problems. |
An amount may have a (single) leading minus sign, but none after that. Bug ledger#2001 (and ledger#1809).
I think this can be closed since PR #2027 got merged. Right? |
Fixed in commit 4ba80c3 |
This works as expected (with a space between '3' and '-')
But this transaction is silently ignored, I guess because the expression incorrectly evaluates to zero
The text was updated successfully, but these errors were encountered: