[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-wallet-webex] 03/04: proper rounding for amount oper
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-wallet-webex] 03/04: proper rounding for amount operations |
Date: |
Sun, 27 Aug 2017 06:48:05 +0200 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository wallet-webex.
commit b47522c11bf5c426f998254f9dc61f0018229b44
Author: Florian Dold <address@hidden>
AuthorDate: Sun Aug 27 05:57:39 2017 +0200
proper rounding for amount operations
---
src/types.ts | 4 ++--
src/wallet.ts | 4 ++++
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/types.ts b/src/types.ts
index 9492d1a7..d016b7fe 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -1312,7 +1312,7 @@ export namespace Amounts {
}
value = value + x.value + Math.floor((fraction + x.fraction) /
fractionalBase);
- fraction = (fraction + x.fraction) % fractionalBase;
+ fraction = Math.floor((fraction + x.fraction) % fractionalBase);
if (value > Number.MAX_SAFE_INTEGER) {
return { amount: getMaxAmount(currency), saturated: true };
}
@@ -1440,7 +1440,7 @@ export namespace Amounts {
export function fromFloat(floatVal: number, currency: string) {
return {
currency,
- fraction: (floatVal - Math.floor(floatVal)) * fractionalBase,
+ fraction: Math.floor((floatVal - Math.floor(floatVal)) * fractionalBase),
value: Math.floor(floatVal),
};
}
diff --git a/src/wallet.ts b/src/wallet.ts
index e7a36f7b..3d095fc0 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -413,6 +413,8 @@ export function selectPayCoins(cds: CoinWithDenom[],
paymentAmount: AmountJson,
denom.feeDeposit).amount) >=
0;
isBelowFee = Amounts.cmp(accFee, depositFeeLimit) <= 0;
+ console.log("coin selection", { coversAmount, isBelowFee, accFee,
accAmount, paymentAmount });
+
if ((coversAmount && isBelowFee) || coversAmountWithFee) {
return cdsResult;
}
@@ -759,6 +761,8 @@ export class Wallet {
cds.push({coin, denom});
}
+ console.log("coin return: selecting from possible coins", { cds, amount }
);
+
return selectPayCoins(cds, amount, amount);
}
--
To stop receiving notification emails like this one, please contact
address@hidden