1 #include "jni.h"
2 #include <android_runtime/AndroidRuntime.h>
3 #include <math.h>
4 #include <float.h>
5 #include "SkTypes.h"
6
7 class MathUtilsGlue {
8 public:
FloorF(JNIEnv * env,jobject clazz,float x)9 static float FloorF(JNIEnv* env, jobject clazz, float x) {
10 return floorf(x);
11 }
12
CeilF(JNIEnv * env,jobject clazz,float x)13 static float CeilF(JNIEnv* env, jobject clazz, float x) {
14 return ceilf(x);
15 }
16
SinF(JNIEnv * env,jobject clazz,float x)17 static float SinF(JNIEnv* env, jobject clazz, float x) {
18 return sinf(x);
19 }
20
CosF(JNIEnv * env,jobject clazz,float x)21 static float CosF(JNIEnv* env, jobject clazz, float x) {
22 return cosf(x);
23 }
24
SqrtF(JNIEnv * env,jobject clazz,float x)25 static float SqrtF(JNIEnv* env, jobject clazz, float x) {
26 return sqrtf(x);
27 }
28
ExpF(JNIEnv * env,jobject clazz,float x)29 static float ExpF(JNIEnv* env, jobject clazz, float x) {
30 return expf(x);
31 }
32
PowF(JNIEnv * env,jobject clazz,float x,float y)33 static float PowF(JNIEnv* env, jobject clazz, float x, float y) {
34 return powf(x, y);
35 }
36
HypotF(JNIEnv * env,jobject clazz,float x,float y)37 static float HypotF(JNIEnv* env, jobject clazz, float x, float y) {
38 return hypotf(x, y);
39 }
40 };
41
42 static 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
register_android_util_FloatMath(JNIEnv * env)53 int 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