[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-merchant-frontend-examples] 02/03: Amount subtractio
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-merchant-frontend-examples] 02/03: Amount subtraction. |
Date: |
Mon, 20 Feb 2017 17:08:07 +0100 |
This is an automated email from the git hooks/post-receive script.
marcello pushed a commit to branch master
in repository merchant-frontend-examples.
commit e5abc1b45040ffb26408b439823a07a2217cee62
Author: Marcello Stanisci <address@hidden>
AuthorDate: Mon Feb 20 17:07:35 2017 +0100
Amount subtraction.
---
Python/pytaler/amounts.py | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/Python/pytaler/amounts.py b/Python/pytaler/amounts.py
index 9c5e83c..d39663f 100644
--- a/Python/pytaler/amounts.py
+++ b/Python/pytaler/amounts.py
@@ -27,3 +27,29 @@ def amount_sum(a1, a2):
"fraction": fractions % FRACTION,
"currency": a1["currency"]}
return ret
+
+# Computes a1 - a2
+def amount_sub(a1, a2):
+ assert(a1["currency"] == a2["currency"])
+
+ # Normalize
+ a1["value"] += int(a1["fraction"] / FRACTION)
+ a2["value"] += int(a2["fraction"] / FRACTION)
+ a1["fraction"] = a1["fraction"] % FRACTION
+ a2["fraction"] = a2["fraction"] % FRACTION
+
+ # Extra care for fraction
+ if a1["fraction"] < a2["fraction"]:
+ a1["fraction"] += FRACTION
+ a1["value"] -= 1
+ assert(a1["value"] >= 0)
+
+ # Sub
+ ret = amount_get_zero(a1["currency"])
+ ret["value"] = a1["value"] - a2["value"]
+ ret["fraction"] = a1["fraction"] - a2["fraction"]
+
+ assert(ret["value"] >= 0)
+ assert(ret["fraction"] >= 0)
+
+ return ret
--
To stop receiving notification emails like this one, please contact
address@hidden