summaryrefslogtreecommitdiffstats
path: root/luni/src/main/native/java_lang_Float.c
diff options
context:
space:
mode:
Diffstat (limited to 'luni/src/main/native/java_lang_Float.c')
-rw-r--r--luni/src/main/native/java_lang_Float.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/luni/src/main/native/java_lang_Float.c b/luni/src/main/native/java_lang_Float.c
new file mode 100644
index 0000000..2a7af21
--- /dev/null
+++ b/luni/src/main/native/java_lang_Float.c
@@ -0,0 +1,85 @@
+//
+// 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* env, jclass clazz, 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* env, jclass clazz, jfloat val)
+{
+ Float f;
+
+ f.f = val;
+
+ return f.bits;
+}
+
+/*
+ * public static native float intBitsToFloat(int bits)
+ */
+static jfloat intBitsToFloat(JNIEnv* env, jclass clazz, jint val)
+{
+ Float f;
+
+ f.bits = val;
+
+ return f.f;
+}
+
+/*
+ * JNI registration
+ */
+static JNINativeMethod gMethods[] = {
+ /* name, signature, funcPtr */
+ { "floatToIntBits", "(F)I", floatToIntBits },
+ { "floatToRawIntBits", "(F)I", floatToRawBits },
+ { "intBitsToFloat", "(I)F", intBitsToFloat },
+};
+int register_java_lang_Float(JNIEnv* env)
+{
+ return jniRegisterNativeMethods(env, "java/lang/Float",
+ gMethods, NELEM(gMethods));
+}
+