diff options
author | John Wiegley <johnw@newartisans.com> | 2004-08-13 17:29:46 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2004-08-13 17:29:46 -0400 |
commit | 0c8dff61edf2db560c92c25468520cd1bc773d77 (patch) | |
tree | 59727c6f574ab9ebe3081d7ed4616efb9d80dd04 /amount.cc | |
parent | 6944e5950a90b17d53a6efe87c71512085d4e1f7 (diff) | |
download | fork-ledger-0c8dff61edf2db560c92c25468520cd1bc773d77.tar.gz fork-ledger-0c8dff61edf2db560c92c25468520cd1bc773d77.tar.bz2 fork-ledger-0c8dff61edf2db560c92c25468520cd1bc773d77.zip |
fixed problem with writing binary amounts
Diffstat (limited to 'amount.cc')
-rw-r--r-- | amount.cc | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -754,6 +754,10 @@ void amount_t::write_quantity(std::ostream& out) const assert(len); out.write((char *)&len, sizeof(len)); out.write(buf, len); +#ifndef WRITE_AMOUNTS_TEXTUALLY + char negative = mpz_sgn(MPZ(quantity)) < 0 ? 1 : 0; + out.write(&negative, sizeof(negative)); +#endif } else { len = 0; out.write((char *)&len, sizeof(len)); @@ -771,7 +775,11 @@ void amount_t::read_quantity(std::istream& in) buf[len] = '\0'; mpz_set_str(MPZ(quantity), buf, 10); #else + char negative; + in.read(&negative, sizeof(negative)); mpz_import(MPZ(quantity), len / sizeof(int), 1, sizeof(int), 0, 0, buf); + if (negative) + mpz_neg(MPZ(quantity), MPZ(quantity)); #endif } else { if (quantity) |