• 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 "JNIHelp.h"
23 
24 #include <stdlib.h>
25 #include <math.h>
26 
27 #define NATIVE_METHOD(className, functionName, signature) \
28 { #functionName, signature, (void*)(className ## _ ## functionName) }
29 
30 JNIEXPORT jdouble JNICALL
Math_cos(JNIEnv * env,jclass unused,jdouble d)31 Math_cos(JNIEnv *env, jclass unused, jdouble d) {
32     return cos(d);
33 }
34 
35 JNIEXPORT jdouble JNICALL
Math_sin(JNIEnv * env,jclass unused,jdouble d)36 Math_sin(JNIEnv *env, jclass unused, jdouble d) {
37     return sin(d);
38 }
39 
40 JNIEXPORT jdouble JNICALL
Math_tan(JNIEnv * env,jclass unused,jdouble d)41 Math_tan(JNIEnv *env, jclass unused, jdouble d) {
42     return tan(d);
43 }
44 
45 JNIEXPORT jdouble JNICALL
Math_asin(JNIEnv * env,jclass unused,jdouble d)46 Math_asin(JNIEnv *env, jclass unused, jdouble d) {
47     return asin(d);
48 }
49 
50 JNIEXPORT jdouble JNICALL
Math_acos(JNIEnv * env,jclass unused,jdouble d)51 Math_acos(JNIEnv *env, jclass unused, jdouble d) {
52     return acos(d);
53 }
54 
55 JNIEXPORT jdouble JNICALL
Math_atan(JNIEnv * env,jclass unused,jdouble d)56 Math_atan(JNIEnv *env, jclass unused, jdouble d) {
57     return atan(d);
58 }
59 
60 JNIEXPORT jdouble JNICALL
Math_exp(JNIEnv * env,jclass unused,jdouble d)61 Math_exp(JNIEnv *env, jclass unused, jdouble d) {
62     return exp(d);
63 }
64 
65 JNIEXPORT jdouble JNICALL
Math_log(JNIEnv * env,jclass unused,jdouble d)66 Math_log(JNIEnv *env, jclass unused, jdouble d) {
67     return log(d);
68 }
69 
70 JNIEXPORT jdouble JNICALL
Math_log10(JNIEnv * env,jclass unused,jdouble d)71 Math_log10(JNIEnv *env, jclass unused, jdouble d) {
72     return log10(d);
73 }
74 
75 JNIEXPORT jdouble JNICALL
Math_sqrt(JNIEnv * env,jclass unused,jdouble d)76 Math_sqrt(JNIEnv *env, jclass unused, jdouble d) {
77     return sqrt(d);
78 }
79 
80 JNIEXPORT jdouble JNICALL
Math_cbrt(JNIEnv * env,jclass unused,jdouble d)81 Math_cbrt(JNIEnv *env, jclass unused, jdouble d) {
82     return cbrt(d);
83 }
84 
85 JNIEXPORT jdouble JNICALL
Math_atan2(JNIEnv * env,jclass unused,jdouble d1,jdouble d2)86 Math_atan2(JNIEnv *env, jclass unused, jdouble d1, jdouble d2) {
87     return atan2(d1, d2);
88 }
89 
90 JNIEXPORT jdouble JNICALL
Math_pow(JNIEnv * env,jclass unused,jdouble d1,jdouble d2)91 Math_pow(JNIEnv *env, jclass unused, jdouble d1, jdouble d2) {
92     return pow(d1, d2);
93 }
94 
95 JNIEXPORT jdouble JNICALL
Math_IEEEremainder(JNIEnv * env,jclass unused,jdouble dividend,jdouble divisor)96 Math_IEEEremainder(JNIEnv *env, jclass unused,
97                                   jdouble dividend,
98                                   jdouble divisor) {
99     return remainder(dividend, divisor);
100 }
101 
102 JNIEXPORT jdouble JNICALL
Math_cosh(JNIEnv * env,jclass unused,jdouble d)103 Math_cosh(JNIEnv *env, jclass unused, jdouble d) {
104     return cosh(d);
105 }
106 
107 JNIEXPORT jdouble JNICALL
Math_sinh(JNIEnv * env,jclass unused,jdouble d)108 Math_sinh(JNIEnv *env, jclass unused, jdouble d) {
109     return sinh(d);
110 }
111 
112 JNIEXPORT jdouble JNICALL
Math_tanh(JNIEnv * env,jclass unused,jdouble d)113 Math_tanh(JNIEnv *env, jclass unused, jdouble d) {
114     return tanh(d);
115 }
116 
117 JNIEXPORT jdouble JNICALL
Math_hypot(JNIEnv * env,jclass unused,jdouble x,jdouble y)118 Math_hypot(JNIEnv *env, jclass unused, jdouble x, jdouble y) {
119     return hypot(x, y);
120 }
121 
122 JNIEXPORT jdouble JNICALL
Math_log1p(JNIEnv * env,jclass unused,jdouble d)123 Math_log1p(JNIEnv *env, jclass unused, jdouble d) {
124     return log1p(d);
125 }
126 
127 JNIEXPORT jdouble JNICALL
Math_expm1(JNIEnv * env,jclass unused,jdouble d)128 Math_expm1(JNIEnv *env, jclass unused, jdouble d) {
129     return expm1(d);
130 }
131 
132 JNIEXPORT jdouble JNICALL
Math_floor(JNIEnv * env,jclass unused,jdouble d)133 Math_floor(JNIEnv *env, jclass unused, jdouble d) {
134     return floor(d);
135 }
136 
137 JNIEXPORT jdouble JNICALL
Math_ceil(JNIEnv * env,jclass unused,jdouble d)138 Math_ceil(JNIEnv *env, jclass unused, jdouble d) {
139     return ceil(d);
140 }
141 
142 JNIEXPORT jdouble JNICALL
Math_rint(JNIEnv * env,jclass unused,jdouble d)143 Math_rint(JNIEnv *env, jclass unused, jdouble d) {
144     return rint(d);
145 }
146 
147 static JNINativeMethod gMethods[] = {
148   NATIVE_METHOD(Math, IEEEremainder, "!(DD)D"),
149   NATIVE_METHOD(Math, acos, "!(D)D"),
150   NATIVE_METHOD(Math, asin, "!(D)D"),
151   NATIVE_METHOD(Math, atan, "!(D)D"),
152   NATIVE_METHOD(Math, atan2, "!(DD)D"),
153   NATIVE_METHOD(Math, cbrt, "!(D)D"),
154   NATIVE_METHOD(Math, cos, "!(D)D"),
155   NATIVE_METHOD(Math, ceil, "!(D)D"),
156   NATIVE_METHOD(Math, cosh, "!(D)D"),
157   NATIVE_METHOD(Math, exp, "!(D)D"),
158   NATIVE_METHOD(Math, expm1, "!(D)D"),
159   NATIVE_METHOD(Math, floor, "!(D)D"),
160   NATIVE_METHOD(Math, hypot, "!(DD)D"),
161   NATIVE_METHOD(Math, log, "!(D)D"),
162   NATIVE_METHOD(Math, log10, "!(D)D"),
163   NATIVE_METHOD(Math, log1p, "!(D)D"),
164   NATIVE_METHOD(Math, pow, "!(DD)D"),
165   NATIVE_METHOD(Math, rint, "!(D)D"),
166   NATIVE_METHOD(Math, sin, "!(D)D"),
167   NATIVE_METHOD(Math, sinh, "!(D)D"),
168   NATIVE_METHOD(Math, sqrt, "!(D)D"),
169   NATIVE_METHOD(Math, tan, "!(D)D"),
170   NATIVE_METHOD(Math, tanh, "!(D)D"),
171 };
172 
register_java_lang_Math(JNIEnv * env)173 void register_java_lang_Math(JNIEnv* env) {
174   jniRegisterNativeMethods(env, "java/lang/Math", gMethods, NELEM(gMethods));
175 }
176