Use intrinsics math floor

This commit is contained in:
TheMode 2021-07-30 18:33:37 +02:00
parent b178a6adac
commit d61174235b
4 changed files with 10 additions and 21 deletions

View File

@ -49,7 +49,7 @@ public interface Point {
*/
@Contract(pure = true)
default int blockX() {
return MathUtils.floor(x());
return (int) Math.floor(x());
}
/**
@ -59,7 +59,7 @@ public interface Point {
*/
@Contract(pure = true)
default int blockY() {
return MathUtils.floor(y());
return (int) Math.floor(y());
}
/**
@ -69,7 +69,7 @@ public interface Point {
*/
@Contract(pure = true)
default int blockZ() {
return MathUtils.floor(z());
return (int) Math.floor(z());
}
/**

View File

@ -536,9 +536,9 @@ public final class Vec implements Point {
);
Operator FLOOR = (x, y, z) -> new Vec(
MathUtils.floor(x),
MathUtils.floor(y),
MathUtils.floor(z)
Math.floor(x),
Math.floor(y),
Math.floor(z)
);
@NotNull Vec apply(double x, double y, double z);

View File

@ -1,9 +1,11 @@
package net.minestom.server.utils;
import org.jetbrains.annotations.ApiStatus;
@ApiStatus.Internal
public final class MathUtils {
private MathUtils() {
}
public static int square(int num) {
@ -91,20 +93,7 @@ public final class MathUtils {
return Math.min(Math.max(value, min), max);
}
public static int floor(double num) {
final int floor = (int) num;
return floor == num ? floor : floor - (int) (Double.doubleToRawLongBits(num) >>> 63);
}
public static double mod(final double a, final double b) {
return (a % b + b) % b;
}
public static Integer tryParse(String string) {
try {
return Integer.parseInt(string);
} catch (NumberFormatException ignored) {
return null;
}
}
}

View File

@ -99,7 +99,7 @@ public final class ChunkUtils {
*/
public static int getChunkCoordinate(double xz) {
assert Chunk.CHUNK_SIZE_X == Chunk.CHUNK_SIZE_Z;
return Math.floorDiv(MathUtils.floor(xz), Chunk.CHUNK_SIZE_X);
return Math.floorDiv((int) Math.floor(xz), Chunk.CHUNK_SIZE_X);
}
/**