gnunet-svn
[Top][All Lists]
Advanced

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

[taler-taler-ios] 15/24: bugfix for inputDigits=0


From: gnunet
Subject: [taler-taler-ios] 15/24: bugfix for inputDigits=0
Date: Tue, 05 Dec 2023 16:26:11 +0100

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

marc-stibane pushed a commit to branch master
in repository taler-ios.

commit b08eb3a442024adaa3c02bc94a4a96191790c287
Author: Marc Stibane <marc@taler.net>
AuthorDate: Mon Dec 4 09:36:59 2023 +0100

    bugfix for inputDigits=0
---
 taler-swift/Sources/taler-swift/Amount.swift | 58 ++++++++++++++++------------
 1 file changed, 34 insertions(+), 24 deletions(-)

diff --git a/taler-swift/Sources/taler-swift/Amount.swift 
b/taler-swift/Sources/taler-swift/Amount.swift
index 0d5a9ba..301f555 100644
--- a/taler-swift/Sources/taler-swift/Amount.swift
+++ b/taler-swift/Sources/taler-swift/Amount.swift
@@ -312,33 +312,43 @@ public final class Amount: Codable, Hashable, @unchecked 
Sendable, CustomStringC
 
     /// Multiplies by ten, then adds digit
     public func shiftLeft(add digit: UInt8, _ inputDigits: UInt) {
-        // how many digits to shift right (e.g. inputD=2 ==> shift:=6)
-        let shift = Self.fractionalBaseDigits - inputDigits
-        // mask to zero out fractions smaller than inputDigits
-        let shiftMask = fractionalBase(shift)
-
-        let carryMask = fractionalBase(Self.fractionalBaseDigits - 1)
-        // get biggest fractional digit
-        let carry = fraction / carryMask
-        var remainder = fraction % carryMask
-//        print("fraction: \(fraction) = \(carry) + \(remainder)")
-
-        let shiftedInt = integer * 10 + UInt64(carry)
-        if shiftedInt < Self.maxValue {
-            self.integer = shiftedInt
-//            print("remainder: \(remainder) / shiftMask \(shiftMask) = 
\(remainder / shiftMask)")
-            remainder = (remainder / shiftMask) * 10
-        } else { // will get too big
-            // Just swap the last significant digit for the one the user typed 
last
-            if shiftMask >= 10 {
-                remainder = (remainder / (shiftMask / 10)) * 10
+        if inputDigits > 0 {
+            // how many digits to shift right (e.g. inputD=2 ==> shift:=6)
+            let shift = Self.fractionalBaseDigits - inputDigits
+            // mask to zero out fractions smaller than inputDigits
+            let shiftMask = fractionalBase(shift)
+
+            let carryMask = fractionalBase(Self.fractionalBaseDigits - 1)
+            // get biggest fractional digit
+            let carry = fraction / carryMask
+            var remainder = fraction % carryMask
+//            print("fraction: \(fraction) = \(carry) + \(remainder)")
+
+            let shiftedInt = integer * 10 + UInt64(carry)
+            if shiftedInt < Self.maxValue {
+                self.integer = shiftedInt
+//                print("remainder: \(remainder) / shiftMask \(shiftMask) = 
\(remainder / shiftMask)")
+                remainder = (remainder / shiftMask) * 10
+            } else { // will get too big
+                     // Just swap the last significant digit for the one the 
user typed last
+                if shiftMask >= 10 {
+                    remainder = (remainder / (shiftMask / 10)) * 10
+                } else {
+                    remainder = (remainder / 10) * 10
+                }
+            }
+            let sum = remainder + UInt32(digit)
+            self.fraction = sum * shiftMask
+   //        print("(remainder: \(remainder) + \(digit)) * base(shift) 
\(shiftMask) = fraction \(fraction)")
+        } else {
+            let shiftedInt = integer * 10 + UInt64(digit)
+            if shiftedInt < Self.maxValue {
+                self.integer = shiftedInt
             } else {
-                remainder = (remainder / 10) * 10
+                self.integer = Self.maxValue
             }
+            self.fraction = 0
         }
-        let sum = remainder + UInt32(digit)
-        self.fraction = sum * shiftMask
-//        print("(remainder: \(remainder) + \(digit)) * base(shift) 
\(shiftMask) = fraction \(fraction)")
     }
 
     /// Sets all fractional digits after inputDigits to 0

-- 
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]