[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-wallet-core] 01/03: fix broken amount multiplication
From: |
gnunet |
Subject: |
[taler-wallet-core] 01/03: fix broken amount multiplication |
Date: |
Thu, 16 Jul 2020 13:52:15 +0200 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository wallet-core.
commit 18f7406d46878e746f41595520426e7b885498f1
Author: Florian Dold <florian.dold@gmail.com>
AuthorDate: Thu Jul 16 17:21:12 2020 +0530
fix broken amount multiplication
---
src/util/amounts.ts | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/src/util/amounts.ts b/src/util/amounts.ts
index c0bb0361..94aefb3c 100644
--- a/src/util/amounts.ts
+++ b/src/util/amounts.ts
@@ -342,22 +342,26 @@ function mult(a: AmountJson, n: number): Result {
if (n == 0) {
return { amount: getZero(a.currency), saturated: false };
}
- let acc = { ...a };
+ let x = a;
+ let acc = getZero(a.currency);
while (n > 1) {
- let r: Result;
if (n % 2 == 0) {
n = n / 2;
- r = add(acc, acc);
} else {
- n = n - 1;
- r = add(acc, a);
+ n = (n - 1) / 2;
+ const r2 = add(acc, x)
+ if (r2.saturated) {
+ return r2;
+ }
+ acc = r2.amount;
}
- if (r.saturated) {
- return r;
+ const r2 = add(x, x);
+ if (r2.saturated) {
+ return r2;
}
- acc = r.amount;
+ x = r2.amount;
}
- return { amount: acc, saturated: false };
+ return add(acc, x);
}
// Export all amount-related functions here for better IDE experience.
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.