use of com.oracle.truffle.espresso.impl.Klass in project graal by oracle.
the class EspressoInterop method fitsInFloat.
@ExportMessage
static boolean fitsInFloat(StaticObject receiver) {
receiver.checkNotForeign();
if (isNull(receiver)) {
return false;
}
Klass klass = receiver.getKlass();
if (isAtMostFloat(klass)) {
return true;
}
Meta meta = klass.getMeta();
/*
* We might lose precision when we convert an int or a long to a float, however, we still
* perform the conversion. This is consistent with Truffle interop, see GR-22718 for more
* details.
*/
if (klass == meta.java_lang_Integer) {
int content = meta.java_lang_Integer_value.getInt(receiver);
float floatContent = content;
return (int) floatContent == content;
}
if (klass == meta.java_lang_Long) {
long content = meta.java_lang_Long_value.getLong(receiver);
float floatContent = content;
return (long) floatContent == content;
}
if (klass == meta.java_lang_Double) {
double content = meta.java_lang_Double_value.getDouble(receiver);
return !Double.isFinite(content) || (float) content == content;
}
return false;
}
Aggregations