Skip to content

Commit

Permalink
Fix edge cases in two artihmetic prims
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Mar 11, 2023
1 parent 8295bae commit 8150566
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public abstract static class PrimDivScalarNode extends AbstractPrimitiveNode imp
protected static final NativeObject doDiv(final NativeObject receiver, final double scalarValue) {
final int[] ints = receiver.getIntStorage();
for (int i = 0; i < ints.length; i++) {
ints[i] = Float.floatToRawIntBits(Float.intBitsToFloat(ints[i]) / (float) scalarValue);
ints[i] = Float.floatToRawIntBits((float) (Float.intBitsToFloat(ints[i]) / scalarValue));
}
return receiver;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1594,7 +1594,7 @@ protected abstract static class AbstractFloatArithmeticPrimitiveNode extends Abs
private static final double LARGE_NUMBER = Math.pow(2, LARGE_NUMBER_EXP);

protected static final double timesToPower(final double matissa, final long exponent) {
return Math.scalb(matissa, MiscUtils.toIntExact(exponent));
return Math.scalb(matissa, (int) MiscUtils.clamp(exponent, Integer.MIN_VALUE, Integer.MAX_VALUE));
}

protected static final long exponentNonZero(final double receiver, final BranchProfile subnormalFloatProfile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public static int bitSplit(final long value, final int offset, final int size) {
return (int) (value >> offset & size - 1);
}

public static long clamp(final long value, final long min, final long max) {
return Math.max(min, Math.min(value, max));
}

@TruffleBoundary
public static long currentTimeMillis() {
return System.currentTimeMillis();
Expand Down

0 comments on commit 8150566

Please sign in to comment.