1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
//
// java_lang_Float.c
// Android
//
// Copyright 2005 The Android Open Source Project
//
#include "JNIHelp.h"
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
typedef union {
unsigned int bits;
float f;
} Float;
#define NaN (0x7fc00000)
/*
* Local helper function.
*/
static int IsNaN(unsigned bits)
{
return ((bits >= 0x7f800001U && bits <= 0x7fffffffU)
|| (bits >= 0xff800001U && bits <= 0xffffffffU));
}
/*
* public static native int floatToIntBits(float value)
*/
static jint floatToIntBits(JNIEnv*, jclass, jfloat val)
{
Float f;
f.f = val;
// For this method all values in the NaN range are
// normalized to the canonical NaN value.
if (IsNaN(f.bits))
f.bits = NaN;
return f.bits;
}
/*
* public static native int floatToRawBits(float value)
*/
static jint floatToRawBits(JNIEnv*, jclass, jfloat val)
{
Float f;
f.f = val;
return f.bits;
}
/*
* public static native float intBitsToFloat(int bits)
*/
static jfloat intBitsToFloat(JNIEnv*, jclass, jint val)
{
Float f;
f.bits = val;
return f.f;
}
static JNINativeMethod gMethods[] = {
{ "floatToIntBits", "(F)I", (void*)floatToIntBits },
{ "floatToRawIntBits", "(F)I", (void*)floatToRawBits },
{ "intBitsToFloat", "(I)F", (void*)intBitsToFloat },
};
int register_java_lang_Float(JNIEnv* env) {
return jniRegisterNativeMethods(env, "java/lang/Float", gMethods, NELEM(gMethods));
}
|