[patterns-instanceof-primitive] RFR: 8303374: Compiler Implementation for Primitive types in patterns, instanceof, and switch [v2]
Raffaello Giulietti
rgiulietti at openjdk.org
Fri Mar 10 17:36:40 UTC 2023
On Fri, 10 Mar 2023 10:43:54 GMT, Aggelos Biboudis <abimpoudis at openjdk.org> wrote:
>> Prototype implementation for primitive types in patterns, instanceof, and switch.
>>
>> draft JEP: https://openjdk.org/jeps/8288476
>>
>> draft spec: https://cr.openjdk.org/~abimpoudis/instanceof/latest/
>
> Aggelos Biboudis has updated the pull request incrementally with one additional commit since the last revision:
>
> Update int_float, long_float, long_double
>
> Co-authored-by: Angelos Bimpoudis <angelos.bimpoudis at oracle.com>
> Co-authored-by: Raffaello Giulietti <raffaello.giulietti at oracle.com>
src/java.base/share/classes/java/lang/runtime/ExactnessMethods.java line 38:
> 36:
> 37: private ExactnessMethods() { }
> 38:
Suggestion:
public static boolean isNegativeZero(float n) {
return Float.floatToIntRawBits(n) == Integer.MIN_VALUE;
}
public static boolean isNegativeZero(double n) {
return Double.doubleToRawLongBits(n) == Long.MIN_VALUE;
}
src/java.base/share/classes/java/lang/runtime/ExactnessMethods.java line 169:
> 167: *
> 168: * */
> 169: public static boolean float_byte(float n) {return Float.compare(n, (float)(byte)(n)) == 0;}
Suggestion:
public static boolean float_byte(float n) {
return n == (float)(byte)n && !isNegativeZero(n);
}
src/java.base/share/classes/java/lang/runtime/ExactnessMethods.java line 177:
> 175: *
> 176: * */
> 177: public static boolean float_short(float n) {return Float.compare(n, (float)(short)(n)) == 0;}
Suggestion:
public static boolean float_short(float n) {
return n == (float)(short)n && !isNegativeZero(n);
}
src/java.base/share/classes/java/lang/runtime/ExactnessMethods.java line 185:
> 183: *
> 184: * */
> 185: public static boolean float_char(float n) {return Float.compare(n, (float)(char)(n)) == 0;}
Suggestion:
public static boolean float_char(float n) {
return n == (float)(char)n && !isNegativeZero(n);
}
src/java.base/share/classes/java/lang/runtime/ExactnessMethods.java line 194:
> 192: * */
> 193: public static boolean float_int(float n) {
> 194: return Double.compare((double)n, (double)((int)n)) == 0;
Suggestion:
return n == (float)(int)n && n != 0x1p31f && !isNegativeZero(n);
src/java.base/share/classes/java/lang/runtime/ExactnessMethods.java line 208:
> 206: Float.compare(n, Float.NEGATIVE_INFINITY) == 0 ||
> 207: Float.compare(n, Float.POSITIVE_INFINITY) == 0) return false;
> 208: return n == (long)n && n != (float)Long.MAX_VALUE + 1;
Suggestion:
return n == (float)(long)n && n != 0x1p63f && !isNegativeZero(n);
src/java.base/share/classes/java/lang/runtime/ExactnessMethods.java line 217:
> 215: *
> 216: * */
> 217: public static boolean double_byte(double n) {return Double.compare(n, (double)(byte)(n)) == 0;}
Suggestion:
public static boolean double_byte(double n) {
return n == (double)(byte)n && !isNegativeZero(n);
}
src/java.base/share/classes/java/lang/runtime/ExactnessMethods.java line 225:
> 223: *
> 224: * */
> 225: public static boolean double_short(double n){return Double.compare(n, (double)(short)(n)) == 0;}
Suggestion:
public static boolean double_short(double n){
return n == (double)(short)n && !isNegativeZero(n);
}
src/java.base/share/classes/java/lang/runtime/ExactnessMethods.java line 233:
> 231: *
> 232: * */
> 233: public static boolean double_char(double n) {return Double.compare(n, (double)(char)(n)) == 0;}
Suggestion:
public static boolean double_char(double n) {
return n == (double)(char)n && !isNegativeZero(n);
}
src/java.base/share/classes/java/lang/runtime/ExactnessMethods.java line 241:
> 239: *
> 240: * */
> 241: public static boolean double_int(double n) {return Double.compare(n, (double)(int)(n)) == 0;}
Suggestion:
public static boolean double_int(double n) {
return n == (double)(int)n && !isNegativeZero(n);
}
src/java.base/share/classes/java/lang/runtime/ExactnessMethods.java line 254:
> 252: Double.compare(n, Double.NEGATIVE_INFINITY) == 0 ||
> 253: Double.compare(n, Double.POSITIVE_INFINITY) == 0) return false;
> 254: return n == (long)n && n != (double)Long.MAX_VALUE + 1;
Suggestion:
return n == (double)(long)n && n != 0x1p63 && !isNegativeZero(n);
src/java.base/share/classes/java/lang/runtime/ExactnessMethods.java line 263:
> 261: *
> 262: * */
> 263: public static boolean double_float(double n) {return Double.compare(n, (double)(float)(n)) == 0;}
Suggestion:
public static boolean double_float(double n) {
return n == (double)(float)n || n != n;
}
-------------
PR: https://git.openjdk.org/amber/pull/91
More information about the amber-dev
mailing list