1 /*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #define LOG_TAG "Math"
18
19 #include "jni.h"
20 #include "JNIHelp.h"
21 #include "JniConstants.h"
22
23 #include <stdlib.h>
24 #include <math.h>
25
Math_sin(JNIEnv *,jclass,jdouble a)26 static jdouble Math_sin(JNIEnv*, jclass, jdouble a) {
27 return sin(a);
28 }
29
Math_cos(JNIEnv *,jclass,jdouble a)30 static jdouble Math_cos(JNIEnv*, jclass, jdouble a) {
31 return cos(a);
32 }
33
Math_tan(JNIEnv *,jclass,jdouble a)34 static jdouble Math_tan(JNIEnv*, jclass, jdouble a) {
35 return tan(a);
36 }
37
Math_asin(JNIEnv *,jclass,jdouble a)38 static jdouble Math_asin(JNIEnv*, jclass, jdouble a) {
39 return asin(a);
40 }
41
Math_acos(JNIEnv *,jclass,jdouble a)42 static jdouble Math_acos(JNIEnv*, jclass, jdouble a) {
43 return acos(a);
44 }
45
Math_atan(JNIEnv *,jclass,jdouble a)46 static jdouble Math_atan(JNIEnv*, jclass, jdouble a) {
47 return atan(a);
48 }
49
Math_exp(JNIEnv *,jclass,jdouble a)50 static jdouble Math_exp(JNIEnv*, jclass, jdouble a) {
51 return exp(a);
52 }
53
Math_log(JNIEnv *,jclass,jdouble a)54 static jdouble Math_log(JNIEnv*, jclass, jdouble a) {
55 return log(a);
56 }
57
Math_IEEEremainder(JNIEnv *,jclass,jdouble a,jdouble b)58 static jdouble Math_IEEEremainder(JNIEnv*, jclass, jdouble a, jdouble b) {
59 return remainder(a, b);
60 }
61
Math_floor(JNIEnv *,jclass,jdouble a)62 static jdouble Math_floor(JNIEnv*, jclass, jdouble a) {
63 return floor(a);
64 }
65
Math_ceil(JNIEnv *,jclass,jdouble a)66 static jdouble Math_ceil(JNIEnv*, jclass, jdouble a) {
67 return ceil(a);
68 }
69
Math_rint(JNIEnv *,jclass,jdouble a)70 static jdouble Math_rint(JNIEnv*, jclass, jdouble a) {
71 return rint(a);
72 }
73
Math_atan2(JNIEnv *,jclass,jdouble a,jdouble b)74 static jdouble Math_atan2(JNIEnv*, jclass, jdouble a, jdouble b) {
75 return atan2(a, b);
76 }
77
Math_pow(JNIEnv *,jclass,jdouble a,jdouble b)78 static jdouble Math_pow(JNIEnv*, jclass, jdouble a, jdouble b) {
79 return pow(a, b);
80 }
81
Math_sinh(JNIEnv *,jclass,jdouble a)82 static jdouble Math_sinh(JNIEnv*, jclass, jdouble a) {
83 return sinh(a);
84 }
85
Math_tanh(JNIEnv *,jclass,jdouble a)86 static jdouble Math_tanh(JNIEnv*, jclass, jdouble a) {
87 return tanh(a);
88 }
89
Math_cosh(JNIEnv *,jclass,jdouble a)90 static jdouble Math_cosh(JNIEnv*, jclass, jdouble a) {
91 return cosh(a);
92 }
93
Math_log10(JNIEnv *,jclass,jdouble a)94 static jdouble Math_log10(JNIEnv*, jclass, jdouble a) {
95 return log10(a);
96 }
97
Math_cbrt(JNIEnv *,jclass,jdouble a)98 static jdouble Math_cbrt(JNIEnv*, jclass, jdouble a) {
99 return cbrt(a);
100 }
101
Math_sqrt(JNIEnv *,jclass,jdouble a)102 static jdouble Math_sqrt(JNIEnv*, jclass, jdouble a) {
103 return sqrt(a);
104 }
105
Math_expm1(JNIEnv *,jclass,jdouble a)106 static jdouble Math_expm1(JNIEnv*, jclass, jdouble a) {
107 return expm1(a);
108 }
109
Math_hypot(JNIEnv *,jclass,jdouble a,jdouble b)110 static jdouble Math_hypot(JNIEnv*, jclass, jdouble a, jdouble b) {
111 return hypot(a, b);
112 }
113
Math_log1p(JNIEnv *,jclass,jdouble a)114 static jdouble Math_log1p(JNIEnv*, jclass, jdouble a) {
115 return log1p(a);
116 }
117
Math_nextafter(JNIEnv *,jclass,jdouble a,jdouble b)118 static jdouble Math_nextafter(JNIEnv*, jclass, jdouble a, jdouble b) {
119 return nextafter(a, b);
120 }
121
122 static JNINativeMethod gMethods[] = {
123 NATIVE_METHOD(Math, IEEEremainder, "!(DD)D"),
124 NATIVE_METHOD(Math, acos, "!(D)D"),
125 NATIVE_METHOD(Math, asin, "!(D)D"),
126 NATIVE_METHOD(Math, atan, "!(D)D"),
127 NATIVE_METHOD(Math, atan2, "!(DD)D"),
128 NATIVE_METHOD(Math, cbrt, "!(D)D"),
129 NATIVE_METHOD(Math, ceil, "!(D)D"),
130 NATIVE_METHOD(Math, cos, "!(D)D"),
131 NATIVE_METHOD(Math, cosh, "!(D)D"),
132 NATIVE_METHOD(Math, exp, "!(D)D"),
133 NATIVE_METHOD(Math, expm1, "!(D)D"),
134 NATIVE_METHOD(Math, floor, "!(D)D"),
135 NATIVE_METHOD(Math, hypot, "!(DD)D"),
136 NATIVE_METHOD(Math, log, "!(D)D"),
137 NATIVE_METHOD(Math, log10, "!(D)D"),
138 NATIVE_METHOD(Math, log1p, "!(D)D"),
139 NATIVE_METHOD(Math, nextafter, "!(DD)D"),
140 NATIVE_METHOD(Math, pow, "!(DD)D"),
141 NATIVE_METHOD(Math, rint, "!(D)D"),
142 NATIVE_METHOD(Math, sin, "!(D)D"),
143 NATIVE_METHOD(Math, sinh, "!(D)D"),
144 NATIVE_METHOD(Math, sqrt, "!(D)D"),
145 NATIVE_METHOD(Math, tan, "!(D)D"),
146 NATIVE_METHOD(Math, tanh, "!(D)D"),
147 };
register_java_lang_Math(JNIEnv * env)148 void register_java_lang_Math(JNIEnv* env) {
149 jniRegisterNativeMethods(env, "java/lang/Math", gMethods, NELEM(gMethods));
150 }
151