From 2b85e4e956c16703b3f38fa770c664f84a725bd1 Mon Sep 17 00:00:00 2001 From: finnm Date: Fri, 10 Jan 2025 14:35:15 +0100 Subject: [PATCH] Updated the power function to use integers --- .../powersort/FinnSort/FasterFinnSort.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/de/uni_marburg/powersort/FinnSort/FasterFinnSort.java b/app/src/main/java/de/uni_marburg/powersort/FinnSort/FasterFinnSort.java index 1f7dc8f..650ed97 100644 --- a/app/src/main/java/de/uni_marburg/powersort/FinnSort/FasterFinnSort.java +++ b/app/src/main/java/de/uni_marburg/powersort/FinnSort/FasterFinnSort.java @@ -459,13 +459,22 @@ public class FasterFinnSort { int n_1 = this.runLen[stackSize - 1]; int n_2 = this.runLen[stackSize]; - double a = ((double) this.runBase[stackSize - 1] + 0.5d * n_1 - 1d) / rangeSize; - double b = ((double) this.runBase[stackSize] + 0.5d * n_2 - 1d) / rangeSize; - int l = 0; - while ((int) (a * pow(2, l)) == (int) (b * pow(2 ,l))) { - l++; + + int a = 2 * this.runBase[stackSize - 1] + n_1; + int b = a + n_1 + n_2; + + int result = 0; + + while (b < rangeSize) { + ++result; + if (a >= rangeSize) { + a -= rangeSize; + b -= rangeSize; + } + a <<= 1; + b <<= 1; } - return l; + return result; } /*