谁有Java源代码中floatToIntBits,intBitsToFloat的源代码?
还有,doubleToLongBits
longBitsToDouble?
这些遵循IEEE754规范。
但是,我无法从Jb中找到他们的source code
问题点数:50、回复次数:4Top
1 楼microflora(Li Yong)回复于 2002-03-08 19:47:34 得分 40
In java they are all native method
So you can't find source code.
Because native methods are implemented in platform depedent way,
e.g. *.dll in windowsTop
2 楼dope(吊儿郎当)回复于 2002-03-08 19:57:11 得分 10
/*
* Find the bit pattern corresponding to a given float, collapsing NaNs
*/
JNIEXPORT jint JNICALL
Java_java_lang_Float_floatToIntBits(JNIEnv *env, jclass unused, jfloat v)
{
union {
int i;
float f;
} u;
if (JVM_IsNaN((float)v)) {
return 0x7fc00000;
}
u.f = (float)v;
return (jint)u.i;
}
这是什么?Top
3 楼keikai(月影)回复于 2002-03-08 20:10:21 得分 0
应该讲第一位老兄说得是对的吧。
第二个,依我的经验看,这个并没有切实反映Java如何将float转换成为int bits的。
在Java的帮助或者source code里面这么注视的:
Returns the bit represention of a single-float value. The result is a representation of the floating-point argument according to the IEEE 754 floating-point "single precision" bit layout. Bit 31 (the bit that is selected by the mask 0x80000000) represents the sign of the floating-point number. Bits 30-23 (the bits that are selected by the mask 0x7f800000) represent the exponent. Bits 22-0 (the bits that are selected by the mask 0x007fffff) represent the significand (sometimes called the mantissa) of the floating-point number. If the argument is positive infinity, the result is 0x7f800000. If the argument is negative infinity, the result is 0xff800000. If the argument is NaN, the result is 0x7fc00000. In all cases, the result is an integer that, when given to the intBitsToFloat(int) method, will produce a floating-point value equal to the argument to floatToIntBitsTop
4 楼dope(吊儿郎当)回复于 2002-03-08 22:59:41 得分 0
在src\share\classes\java\lang下float.java中,floatToIntBits为native方法,就是说实现与平台相关,应在c文件中。
在src\share\native\java\lang下float.c中的Java_java_lang_Float_floatToIntBits函数使用了union,输入为float,返回为int。
所以我认为这儿就是floatToIntBits的实现方法。Top




