From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: MrHua269 Date: Sun, 12 Jan 2025 14:15:24 +0800 Subject: [PATCH] Gale: Use platform math functions Co-authored by: Martijn Muijsers , Xymb As part of: Gale (https://github.com/GaleMC/Gale/blob/276e903b2688f23b19bdc8d493c0bf87656d2400/patches/server/0019-Use-platform-math-functions.patch) and Kaiiju(https://github.com/KaiijuMC/Kaiiju) Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html) diff --git a/net/minecraft/util/Mth.java b/net/minecraft/util/Mth.java index d5d8134da9423cec199cf44762460104677194d6..e0eed27cb33348fcb46858c40014b5fe5dbaf426 100644 --- a/net/minecraft/util/Mth.java +++ b/net/minecraft/util/Mth.java @@ -58,18 +58,15 @@ public class Mth { } public static int floor(float value) { - int i = (int)value; - return value < i ? i - 1 : i; + return (int) Math.floor(value); // Gale - use platform math functions } public static int floor(double value) { - int i = (int)value; - return value < i ? i - 1 : i; + return (int) Math.floor(value); // Gale - use platform math functions } public static long lfloor(double value) { - long l = (long)value; - return value < l ? l - 1L : l; + return (long) Math.floor(value); // Gale - use platform math functions } public static float abs(float value) { @@ -81,13 +78,11 @@ public class Mth { } public static int ceil(float value) { - int i = (int)value; - return value > i ? i + 1 : i; + return (int) Math.ceil(value); // Gale - use platform math functions } public static int ceil(double value) { - int i = (int)value; - return value > i ? i + 1 : i; + return (int) Math.ceil(value); // Gale - use platform math functions } public static int clamp(int value, int min, int max) { @@ -123,15 +118,7 @@ public class Mth { } public static double absMax(double x, double y) { - if (x < 0.0) { - x = -x; - } - - if (y < 0.0) { - y = -y; - } - - return Math.max(x, y); + return Math.max(Math.abs(x), Math.abs(y)); // Gale - use platform math functions } public static int floorDiv(int dividend, int divisor) {