android_util_FloatMath.cpp revision 270e3381e7053c3b15aa8f508c9df9d98032cd62
1#include "jni.h"
2#include <android_runtime/AndroidRuntime.h>
3#include <math.h>
4#include <float.h>
5#include "SkTypes.h"
6
7class MathUtilsGlue {
8public:
9    static float FloorF(JNIEnv* env, jobject clazz, float x) {
10        return floorf(x);
11    }
12
13    static float CeilF(JNIEnv* env, jobject clazz, float x) {
14        return ceilf(x);
15    }
16
17    static float SinF(JNIEnv* env, jobject clazz, float x) {
18        return sinf(x);
19    }
20
21    static float CosF(JNIEnv* env, jobject clazz, float x) {
22        return cosf(x);
23    }
24
25    static float SqrtF(JNIEnv* env, jobject clazz, float x) {
26        return sqrtf(x);
27    }
28
29    static float ExpF(JNIEnv* env, jobject clazz, float x) {
30        return expf(x);
31    }
32
33    static float HypotF(JNIEnv* env, jobject clazz, float x, float y) {
34        return hypotf(x, y);
35    }
36};
37
38static JNINativeMethod gMathUtilsMethods[] = {
39    {"floor", "(F)F", (void*) MathUtilsGlue::FloorF},
40    {"ceil", "(F)F", (void*) MathUtilsGlue::CeilF},
41    {"sin", "(F)F", (void*) MathUtilsGlue::SinF},
42    {"cos", "(F)F", (void*) MathUtilsGlue::CosF},
43    {"sqrt", "(F)F", (void*) MathUtilsGlue::SqrtF},
44    {"exp", "(F)F", (void*) MathUtilsGlue::ExpF},
45    {"hypot", "(FF)F", (void*) MathUtilsGlue::HypotF},
46};
47
48int register_android_util_FloatMath(JNIEnv* env)
49{
50    int result = android::AndroidRuntime::registerNativeMethods(env,
51                                            "android/util/FloatMath",
52                                            gMathUtilsMethods,
53                                            SK_ARRAY_COUNT(gMathUtilsMethods));
54    return result;
55}
56
57