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 PowF(JNIEnv* env, jobject clazz, float x, float y) {
34        return powf(x, y);
35    }
36
37    static float HypotF(JNIEnv* env, jobject clazz, float x, float y) {
38        return hypotf(x, y);
39    }
40};
41
42static JNINativeMethod gMathUtilsMethods[] = {
43    {"floor", "(F)F", (void*) MathUtilsGlue::FloorF},
44    {"ceil", "(F)F", (void*) MathUtilsGlue::CeilF},
45    {"sin", "(F)F", (void*) MathUtilsGlue::SinF},
46    {"cos", "(F)F", (void*) MathUtilsGlue::CosF},
47    {"sqrt", "(F)F", (void*) MathUtilsGlue::SqrtF},
48    {"exp", "(F)F", (void*) MathUtilsGlue::ExpF},
49    {"pow", "(FF)F", (void*) MathUtilsGlue::PowF},
50    {"hypot", "(FF)F", (void*) MathUtilsGlue::HypotF},
51};
52
53int register_android_util_FloatMath(JNIEnv* env)
54{
55    int result = android::AndroidRuntime::registerNativeMethods(env,
56                                            "android/util/FloatMath",
57                                            gMathUtilsMethods,
58                                            SK_ARRAY_COUNT(gMathUtilsMethods));
59    return result;
60}
61
62