1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * This code is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 2 only, as
6  * published by the Free Software Foundation.  The Android Open Source
7  * Project designates this particular file as subject to the "Classpath"
8  * exception as provided by The Android Open Source Project in the LICENSE
9  * file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #include "jni.h"
23 #include <nativehelper/JNIHelp.h>
24 #include "nativehelper/jni_macros.h"
25 
26 #include <stdlib.h>
27 #include <math.h>
28 
29 JNIEXPORT jdouble JNICALL
Math_cos(jdouble d)30 Math_cos(jdouble d) {
31     return cos(d);
32 }
33 
34 JNIEXPORT jdouble JNICALL
Math_sin(jdouble d)35 Math_sin(jdouble d) {
36     return sin(d);
37 }
38 
39 JNIEXPORT jdouble JNICALL
Math_tan(jdouble d)40 Math_tan(jdouble d) {
41     return tan(d);
42 }
43 
44 JNIEXPORT jdouble JNICALL
Math_asin(jdouble d)45 Math_asin(jdouble d) {
46     return asin(d);
47 }
48 
49 JNIEXPORT jdouble JNICALL
Math_acos(jdouble d)50 Math_acos(jdouble d) {
51     return acos(d);
52 }
53 
54 JNIEXPORT jdouble JNICALL
Math_atan(jdouble d)55 Math_atan(jdouble d) {
56     return atan(d);
57 }
58 
59 JNIEXPORT jdouble JNICALL
Math_exp(jdouble d)60 Math_exp(jdouble d) {
61     return exp(d);
62 }
63 
64 JNIEXPORT jdouble JNICALL
Math_log(jdouble d)65 Math_log(jdouble d) {
66     return log(d);
67 }
68 
69 JNIEXPORT jdouble JNICALL
Math_log10(jdouble d)70 Math_log10(jdouble d) {
71     return log10(d);
72 }
73 
74 JNIEXPORT jdouble JNICALL
Math_sqrt(jdouble d)75 Math_sqrt(jdouble d) {
76     return sqrt(d);
77 }
78 
79 JNIEXPORT jdouble JNICALL
Math_cbrt(jdouble d)80 Math_cbrt(jdouble d) {
81     return cbrt(d);
82 }
83 
84 JNIEXPORT jdouble JNICALL
Math_atan2(jdouble d1,jdouble d2)85 Math_atan2(jdouble d1, jdouble d2) {
86     return atan2(d1, d2);
87 }
88 
89 JNIEXPORT jdouble JNICALL
Math_pow(jdouble d1,jdouble d2)90 Math_pow(jdouble d1, jdouble d2) {
91     return pow(d1, d2);
92 }
93 
94 JNIEXPORT jdouble JNICALL
Math_IEEEremainder(jdouble dividend,jdouble divisor)95 Math_IEEEremainder(jdouble dividend, jdouble divisor) {
96     return remainder(dividend, divisor);
97 }
98 
99 JNIEXPORT jdouble JNICALL
Math_cosh(jdouble d)100 Math_cosh(jdouble d) {
101     return cosh(d);
102 }
103 
104 JNIEXPORT jdouble JNICALL
Math_sinh(jdouble d)105 Math_sinh(jdouble d) {
106     return sinh(d);
107 }
108 
109 JNIEXPORT jdouble JNICALL
Math_tanh(jdouble d)110 Math_tanh(jdouble d) {
111     return tanh(d);
112 }
113 
114 JNIEXPORT jdouble JNICALL
Math_hypot(jdouble x,jdouble y)115 Math_hypot(jdouble x, jdouble y) {
116     return hypot(x, y);
117 }
118 
119 JNIEXPORT jdouble JNICALL
Math_log1p(jdouble d)120 Math_log1p(jdouble d) {
121     return log1p(d);
122 }
123 
124 JNIEXPORT jdouble JNICALL
Math_expm1(jdouble d)125 Math_expm1(jdouble d) {
126     return expm1(d);
127 }
128 
129 JNIEXPORT jdouble JNICALL
Math_floor(jdouble d)130 Math_floor(jdouble d) {
131     return floor(d);
132 }
133 
134 JNIEXPORT jdouble JNICALL
Math_ceil(jdouble d)135 Math_ceil(jdouble d) {
136     return ceil(d);
137 }
138 
139 JNIEXPORT jdouble JNICALL
Math_rint(jdouble d)140 Math_rint(jdouble d) {
141     return rint(d);
142 }
143 
144 static JNINativeMethod gMethods[] = {
145   FAST_NATIVE_METHOD(Math, IEEEremainder, "(DD)D"),
146   FAST_NATIVE_METHOD(Math, acos, "(D)D"),
147   FAST_NATIVE_METHOD(Math, asin, "(D)D"),
148   FAST_NATIVE_METHOD(Math, atan, "(D)D"),
149   FAST_NATIVE_METHOD(Math, atan2, "(DD)D"),
150   FAST_NATIVE_METHOD(Math, cbrt, "(D)D"),
151   FAST_NATIVE_METHOD(Math, cos, "(D)D"),
152   FAST_NATIVE_METHOD(Math, ceil, "(D)D"),
153   FAST_NATIVE_METHOD(Math, cosh, "(D)D"),
154   FAST_NATIVE_METHOD(Math, exp, "(D)D"),
155   FAST_NATIVE_METHOD(Math, expm1, "(D)D"),
156   FAST_NATIVE_METHOD(Math, floor, "(D)D"),
157   FAST_NATIVE_METHOD(Math, hypot, "(DD)D"),
158   FAST_NATIVE_METHOD(Math, log, "(D)D"),
159   FAST_NATIVE_METHOD(Math, log10, "(D)D"),
160   FAST_NATIVE_METHOD(Math, log1p, "(D)D"),
161   FAST_NATIVE_METHOD(Math, pow, "(DD)D"),
162   FAST_NATIVE_METHOD(Math, rint, "(D)D"),
163   FAST_NATIVE_METHOD(Math, sin, "(D)D"),
164   FAST_NATIVE_METHOD(Math, sinh, "(D)D"),
165   FAST_NATIVE_METHOD(Math, sqrt, "(D)D"),
166   FAST_NATIVE_METHOD(Math, tan, "(D)D"),
167   FAST_NATIVE_METHOD(Math, tanh, "(D)D"),
168 };
169 
register_java_lang_Math(JNIEnv * env)170 void register_java_lang_Math(JNIEnv* env) {
171   jniRegisterNativeMethods(env, "java/lang/Math", gMethods, NELEM(gMethods));
172 }
173