From 5c58c83adad6f0e9abe19eab0895cbe030b2b6a9 Mon Sep 17 00:00:00 2001 From: cytrek-betoniarek Date: Tue, 5 Dec 2023 16:26:57 +0100 Subject: [PATCH 1/2] Fix the scale method (#72401) --- .../java/jenkins/advancedqueue/PriorityCalculationsUtil.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/jenkins/advancedqueue/PriorityCalculationsUtil.java b/src/main/java/jenkins/advancedqueue/PriorityCalculationsUtil.java index 85481e96..3ffecf2e 100644 --- a/src/main/java/jenkins/advancedqueue/PriorityCalculationsUtil.java +++ b/src/main/java/jenkins/advancedqueue/PriorityCalculationsUtil.java @@ -13,6 +13,10 @@ public static int scale(int oldmax, int newmax, int value) { return PRIORITY_USE_DEFAULT_PRIORITY; } float p = ((float) (value - 1) / (float) (oldmax - 1)); + float eps = (float)0.0001; + if(p*(newmax - 1) > Math.round(p*(newmax - 1)) - eps && p*(newmax - 1) < Math.round(p*(newmax - 1)) + eps){ + return (int) (Math.round(p * (newmax - 1))) + 1; + } if (p <= 0.5) { return (int) (Math.floor(p * (newmax - 1))) + 1; } From f9d6545f449f5b6e9472c72ddcede67228e50065 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sat, 9 Dec 2023 04:18:03 -0700 Subject: [PATCH 2/2] Fix formatting --- .../java/jenkins/advancedqueue/PriorityCalculationsUtil.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/jenkins/advancedqueue/PriorityCalculationsUtil.java b/src/main/java/jenkins/advancedqueue/PriorityCalculationsUtil.java index 3ffecf2e..8af95921 100644 --- a/src/main/java/jenkins/advancedqueue/PriorityCalculationsUtil.java +++ b/src/main/java/jenkins/advancedqueue/PriorityCalculationsUtil.java @@ -13,8 +13,9 @@ public static int scale(int oldmax, int newmax, int value) { return PRIORITY_USE_DEFAULT_PRIORITY; } float p = ((float) (value - 1) / (float) (oldmax - 1)); - float eps = (float)0.0001; - if(p*(newmax - 1) > Math.round(p*(newmax - 1)) - eps && p*(newmax - 1) < Math.round(p*(newmax - 1)) + eps){ + float eps = (float) 0.0001; + if (p * (newmax - 1) > Math.round(p * (newmax - 1)) - eps + && p * (newmax - 1) < Math.round(p * (newmax - 1)) + eps) { return (int) (Math.round(p * (newmax - 1))) + 1; } if (p <= 0.5) {