fix broken amount multiplication
This commit is contained in:
parent
bcd9e2e5ff
commit
18f7406d46
@ -342,22 +342,26 @@ function mult(a: AmountJson, n: number): Result {
|
|||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
return { amount: getZero(a.currency), saturated: false };
|
return { amount: getZero(a.currency), saturated: false };
|
||||||
}
|
}
|
||||||
let acc = { ...a };
|
let x = a;
|
||||||
|
let acc = getZero(a.currency);
|
||||||
while (n > 1) {
|
while (n > 1) {
|
||||||
let r: Result;
|
|
||||||
if (n % 2 == 0) {
|
if (n % 2 == 0) {
|
||||||
n = n / 2;
|
n = n / 2;
|
||||||
r = add(acc, acc);
|
|
||||||
} else {
|
} else {
|
||||||
n = n - 1;
|
n = (n - 1) / 2;
|
||||||
r = add(acc, a);
|
const r2 = add(acc, x)
|
||||||
|
if (r2.saturated) {
|
||||||
|
return r2;
|
||||||
}
|
}
|
||||||
if (r.saturated) {
|
acc = r2.amount;
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
acc = r.amount;
|
const r2 = add(x, x);
|
||||||
|
if (r2.saturated) {
|
||||||
|
return r2;
|
||||||
}
|
}
|
||||||
return { amount: acc, saturated: false };
|
x = r2.amount;
|
||||||
|
}
|
||||||
|
return add(acc, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export all amount-related functions here for better IDE experience.
|
// Export all amount-related functions here for better IDE experience.
|
||||||
|
Loading…
Reference in New Issue
Block a user