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