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