From d270a86017603319f8feb5495353278ecf96766f Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Thu, 16 Jan 2020 18:12:45 -0800 Subject: [PATCH] Fix safeDoubleToFloat for values <= 0 MIN_VALUE is actually the positive closest-to-zero value that a float can represent. So this function would break on 0 and negative float values. --- src/it/unimi/dsi/fastutil/SafeMath.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/it/unimi/dsi/fastutil/SafeMath.java b/src/it/unimi/dsi/fastutil/SafeMath.java index 63ee6bfa6..0e6b372b8 100644 --- a/src/it/unimi/dsi/fastutil/SafeMath.java +++ b/src/it/unimi/dsi/fastutil/SafeMath.java @@ -42,7 +42,7 @@ public static int safeLongToInt(final long value) { public static float safeDoubleToFloat(final double value) { if (Double.isNaN(value)) return Float.NaN; if (Double.isInfinite(value)) return value < 0.0d ? Float.NEGATIVE_INFINITY : Float.POSITIVE_INFINITY; - if (value < Float.MIN_VALUE || Float.MAX_VALUE < value) throw new IllegalArgumentException(value + " can't be represented as float (out of range)"); + if (value < -Float.MAX_VALUE || Float.MAX_VALUE < value) throw new IllegalArgumentException(value + " can't be represented as float (out of range)"); final float floatValue = (float) value; if (floatValue != value) throw new IllegalArgumentException(value + " can't be represented as float (imprecise)"); return floatValue;