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