Jlong conversions
-----------------
Casting a jlong to a jlong is unnecessary and does not work if a jlong is a
structure.
src\share\native\java\lang\double.c
/*
* Find the double float corresponding to a given bit pattern
*/
JNIEXPORT jdouble JNICALL
Java_java_lang_Double_longBitsToDouble(JNIEnv *env, jclass unused, jlong v)
{
union {
jlong l;
double d;
} u;
jlong_to_jdouble_bits(&v);
#if defined IBM_ALL /*ibm*/
u.l = v;
#else /*ibm*/
u.l = (jlong)v;
#endif /*ibm*/
return (jdouble)u.d;
}
/*
* Find the bit pattern corresponding to a given double float
*/
JNIEXPORT jlong JNICALL
Java_java_lang_Double_doubleToLongBits(JNIEnv *env, jclass unused, jdouble v)
{
union {
jlong l;
double d;
} u;
if (JVM_IsNan((double)v)) {
u.l = jint_to_jlong(0x7ff80000);
return jlong_shl(u.l, 32);
}
jdouble_to_jlong_bits(&v);
u.d = (double)v;
#if defined IBM_ALL /*ibm*/
return u.l;
#else /*ibm*/
return (jlong)u.l;
#endif /*ibm*/
}
-----------------
Casting a jlong to a jlong is unnecessary and does not work if a jlong is a
structure.
src\share\native\java\lang\double.c
/*
* Find the double float corresponding to a given bit pattern
*/
JNIEXPORT jdouble JNICALL
Java_java_lang_Double_longBitsToDouble(JNIEnv *env, jclass unused, jlong v)
{
union {
jlong l;
double d;
} u;
jlong_to_jdouble_bits(&v);
#if defined IBM_ALL /*ibm*/
u.l = v;
#else /*ibm*/
u.l = (jlong)v;
#endif /*ibm*/
return (jdouble)u.d;
}
/*
* Find the bit pattern corresponding to a given double float
*/
JNIEXPORT jlong JNICALL
Java_java_lang_Double_doubleToLongBits(JNIEnv *env, jclass unused, jdouble v)
{
union {
jlong l;
double d;
} u;
if (JVM_IsNan((double)v)) {
u.l = jint_to_jlong(0x7ff80000);
return jlong_shl(u.l, 32);
}
jdouble_to_jlong_bits(&v);
u.d = (double)v;
#if defined IBM_ALL /*ibm*/
return u.l;
#else /*ibm*/
return (jlong)u.l;
#endif /*ibm*/
}
- duplicates
-
JDK-4110531 (porting) use of jlong and int64_t must always use macros
-
- Closed
-