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