mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
6506405: Math.abs(float) is slow
Reviewed-by: darcy
This commit is contained in:
parent
357fe09f2e
commit
c0d4efff3c
4 changed files with 129 additions and 8 deletions
|
@ -1527,7 +1527,8 @@ public final class Math {
|
|||
*/
|
||||
@IntrinsicCandidate
|
||||
public static float abs(float a) {
|
||||
return (a <= 0.0F) ? 0.0F - a : a;
|
||||
// Convert to bit field form, zero the sign bit, and convert back
|
||||
return Float.intBitsToFloat(Float.floatToRawIntBits(a) & FloatConsts.MAG_BIT_MASK);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1552,7 +1553,9 @@ public final class Math {
|
|||
*/
|
||||
@IntrinsicCandidate
|
||||
public static double abs(double a) {
|
||||
return (a <= 0.0D) ? 0.0D - a : a;
|
||||
// Convert to bit field form, zero the sign bit, and convert back
|
||||
return Double.longBitsToDouble(Double.doubleToRawLongBits(a) & DoubleConsts.MAG_BIT_MASK);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue