gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-exchange] branch master updated: -fix rouding


From: gnunet
Subject: [taler-exchange] branch master updated: -fix rouding
Date: Fri, 17 Nov 2023 21:28:38 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository exchange.

The following commit(s) were added to refs/heads/master by this push:
     new e3cd49d3 -fix rouding
e3cd49d3 is described below

commit e3cd49d353941624a08d3c79b8da32b106bfd742
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Fri Nov 17 21:28:33 2023 +0100

    -fix rouding
---
 contrib/gana                  |  2 +-
 contrib/wallet-core           |  2 +-
 src/lib/exchange_api_stefan.c | 28 ++++++++++++++++++----------
 3 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/contrib/gana b/contrib/gana
index 22ef218b..27de0765 160000
--- a/contrib/gana
+++ b/contrib/gana
@@ -1 +1 @@
-Subproject commit 22ef218ba8da81d60b5fb1fa641c86ec20a09a31
+Subproject commit 27de076550489d6ca0b99822121579e02fee4cf2
diff --git a/contrib/wallet-core b/contrib/wallet-core
index 4cfef06e..621dad2c 160000
--- a/contrib/wallet-core
+++ b/contrib/wallet-core
@@ -1 +1 @@
-Subproject commit 4cfef06e890f1e556027c9e294a9c7736ec1ecbf
+Subproject commit 621dad2c2ec9a2adc52076cebf65891d6764c802
diff --git a/src/lib/exchange_api_stefan.c b/src/lib/exchange_api_stefan.c
index 6f6c3f2c..226bca82 100644
--- a/src/lib/exchange_api_stefan.c
+++ b/src/lib/exchange_api_stefan.c
@@ -299,22 +299,30 @@ TALER_EXCHANGE_keys_stefan_round (
   struct TALER_Amount *val)
 {
   const struct TALER_Amount *min;
-  uint32_t mod = 1;
+  uint32_t mod;
   uint32_t frac;
-  uint32_t rst;
+  uint32_t lim;
 
+  if (0 == val->fraction)
+  {
+    /* rounding of non-fractions not supported */
+    return;
+  }
   min = get_unit (keys);
   if (NULL == min)
     return;
-  frac = min->fraction;
-  while (0 != frac % 10)
+  if (0 == min->fraction)
+  {
+    frac = TALER_AMOUNT_FRAC_BASE;
+  }
+  else
   {
-    mod *= 10;
-    frac /= 10;
+    frac = min->fraction;
   }
-  rst = val->fraction % mod;
-  if (rst < mod / 2)
-    val->fraction -= rst;
+  lim = frac / 2;
+  mod = val->fraction % frac;
+  if (mod < lim)
+    val->fraction -= mod; /* round down */
   else
-    val->fraction += mod - rst;
+    val->fraction += frac - mod; /* round up */
 }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]