Skip to content

Commit

Permalink
Merge pull request #143 from Spottedleaf/patch-1
Browse files Browse the repository at this point in the history
Fix SafeMath#safeDoubleToFloat for values <= 0
  • Loading branch information
vigna committed Jun 4, 2020
2 parents 31c13ab + d270a86 commit 938d7fa
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/it/unimi/dsi/fastutil/SafeMath.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 938d7fa

Please sign in to comment.