1 /*
2 * Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 #include "jni.h"
27 #include "../../external/fdlibm/fdlibm.h"
28
29 #include "JNIHelp.h"
30
31 #define NATIVE_METHOD(className, functionName, signature) \
32 { #functionName, signature, (void*)(className ## _ ## functionName) }
33
34
35 JNIEXPORT jdouble JNICALL
StrictMath_cos(JNIEnv * env,jclass unused,jdouble d)36 StrictMath_cos(JNIEnv *env, jclass unused, jdouble d)
37 {
38 return (jdouble) ieee_cos((double)d);
39 }
40
41 JNIEXPORT jdouble JNICALL
StrictMath_sin(JNIEnv * env,jclass unused,jdouble d)42 StrictMath_sin(JNIEnv *env, jclass unused, jdouble d)
43 {
44 return (jdouble) ieee_sin((double)d);
45 }
46
47 JNIEXPORT jdouble JNICALL
StrictMath_tan(JNIEnv * env,jclass unused,jdouble d)48 StrictMath_tan(JNIEnv *env, jclass unused, jdouble d)
49 {
50 return (jdouble) ieee_tan((double)d);
51 }
52
53 JNIEXPORT jdouble JNICALL
StrictMath_asin(JNIEnv * env,jclass unused,jdouble d)54 StrictMath_asin(JNIEnv *env, jclass unused, jdouble d)
55 {
56 return (jdouble) ieee_asin((double)d);
57 }
58
59 JNIEXPORT jdouble JNICALL
StrictMath_acos(JNIEnv * env,jclass unused,jdouble d)60 StrictMath_acos(JNIEnv *env, jclass unused, jdouble d)
61 {
62 return (jdouble) ieee_acos((double)d);
63 }
64
65 JNIEXPORT jdouble JNICALL
StrictMath_atan(JNIEnv * env,jclass unused,jdouble d)66 StrictMath_atan(JNIEnv *env, jclass unused, jdouble d)
67 {
68 return (jdouble) ieee_atan((double)d);
69 }
70
71 JNIEXPORT jdouble JNICALL
StrictMath_exp(JNIEnv * env,jclass unused,jdouble d)72 StrictMath_exp(JNIEnv *env, jclass unused, jdouble d)
73 {
74 return (jdouble) ieee_exp((double)d);
75 }
76
77 JNIEXPORT jdouble JNICALL
StrictMath_log(JNIEnv * env,jclass unused,jdouble d)78 StrictMath_log(JNIEnv *env, jclass unused, jdouble d)
79 {
80 return (jdouble) ieee_log((double)d);
81 }
82
83 JNIEXPORT jdouble JNICALL
StrictMath_log10(JNIEnv * env,jclass unused,jdouble d)84 StrictMath_log10(JNIEnv *env, jclass unused, jdouble d)
85 {
86 return (jdouble) ieee_log10((double)d);
87 }
88
89 JNIEXPORT jdouble JNICALL
StrictMath_sqrt(JNIEnv * env,jclass unused,jdouble d)90 StrictMath_sqrt(JNIEnv *env, jclass unused, jdouble d)
91 {
92 return (jdouble) ieee_sqrt((double)d);
93 }
94
95 JNIEXPORT jdouble JNICALL
StrictMath_cbrt(JNIEnv * env,jclass unused,jdouble d)96 StrictMath_cbrt(JNIEnv *env, jclass unused, jdouble d)
97 {
98 return (jdouble) ieee_cbrt((double)d);
99 }
100
101 JNIEXPORT jdouble JNICALL
StrictMath_atan2(JNIEnv * env,jclass unused,jdouble d1,jdouble d2)102 StrictMath_atan2(JNIEnv *env, jclass unused, jdouble d1, jdouble d2)
103 {
104 return (jdouble) ieee_atan2((double)d1, (double)d2);
105 }
106
107 JNIEXPORT jdouble JNICALL
StrictMath_pow(JNIEnv * env,jclass unused,jdouble d1,jdouble d2)108 StrictMath_pow(JNIEnv *env, jclass unused, jdouble d1, jdouble d2)
109 {
110 return (jdouble) ieee_pow((double)d1, (double)d2);
111 }
112
113 JNIEXPORT jdouble JNICALL
StrictMath_IEEEremainder(JNIEnv * env,jclass unused,jdouble dividend,jdouble divisor)114 StrictMath_IEEEremainder(JNIEnv *env, jclass unused,
115 jdouble dividend,
116 jdouble divisor)
117 {
118 return (jdouble) ieee_remainder(dividend, divisor);
119 }
120
121 JNIEXPORT jdouble JNICALL
StrictMath_cosh(JNIEnv * env,jclass unused,jdouble d)122 StrictMath_cosh(JNIEnv *env, jclass unused, jdouble d)
123 {
124 return (jdouble) ieee_cosh((double)d);
125 }
126
127 JNIEXPORT jdouble JNICALL
StrictMath_sinh(JNIEnv * env,jclass unused,jdouble d)128 StrictMath_sinh(JNIEnv *env, jclass unused, jdouble d)
129 {
130 return (jdouble) ieee_sinh((double)d);
131 }
132
133 JNIEXPORT jdouble JNICALL
StrictMath_tanh(JNIEnv * env,jclass unused,jdouble d)134 StrictMath_tanh(JNIEnv *env, jclass unused, jdouble d)
135 {
136 return (jdouble) ieee_tanh((double)d);
137 }
138
139 JNIEXPORT jdouble JNICALL
StrictMath_hypot(JNIEnv * env,jclass unused,jdouble x,jdouble y)140 StrictMath_hypot(JNIEnv *env, jclass unused, jdouble x, jdouble y)
141 {
142 return (jdouble) ieee_hypot((double)x, (double)y);
143 }
144
145
146
147 JNIEXPORT jdouble JNICALL
StrictMath_log1p(JNIEnv * env,jclass unused,jdouble d)148 StrictMath_log1p(JNIEnv *env, jclass unused, jdouble d)
149 {
150 return (jdouble) ieee_log1p((double)d);
151 }
152
153 JNIEXPORT jdouble JNICALL
StrictMath_expm1(JNIEnv * env,jclass unused,jdouble d)154 StrictMath_expm1(JNIEnv *env, jclass unused, jdouble d)
155 {
156 return (jdouble) ieee_expm1((double)d);
157 }
158
159 static JNINativeMethod gMethods[] = {
160 NATIVE_METHOD(StrictMath, cos, "(D)D"),
161 NATIVE_METHOD(StrictMath, sin, "(D)D"),
162 NATIVE_METHOD(StrictMath, tan, "(D)D"),
163 NATIVE_METHOD(StrictMath, asin, "(D)D"),
164 NATIVE_METHOD(StrictMath, acos, "(D)D"),
165 NATIVE_METHOD(StrictMath, atan, "(D)D"),
166 NATIVE_METHOD(StrictMath, exp, "(D)D"),
167 NATIVE_METHOD(StrictMath, log, "(D)D"),
168 NATIVE_METHOD(StrictMath, log10, "(D)D"),
169 NATIVE_METHOD(StrictMath, sqrt, "(D)D"),
170 NATIVE_METHOD(StrictMath, cbrt, "(D)D"),
171 NATIVE_METHOD(StrictMath, atan2, "(DD)D"),
172 NATIVE_METHOD(StrictMath, pow, "(DD)D"),
173 NATIVE_METHOD(StrictMath, IEEEremainder, "(DD)D"),
174 NATIVE_METHOD(StrictMath, cosh, "(D)D"),
175 NATIVE_METHOD(StrictMath, sinh, "(D)D"),
176 NATIVE_METHOD(StrictMath, tanh, "(D)D"),
177 NATIVE_METHOD(StrictMath, hypot, "(DD)D"),
178 NATIVE_METHOD(StrictMath, log1p, "(D)D"),
179 NATIVE_METHOD(StrictMath, expm1, "(D)D"),
180 };
181
register_java_lang_StrictMath(JNIEnv * env)182 void register_java_lang_StrictMath(JNIEnv* env) {
183 jniRegisterNativeMethods(env, "java/lang/StrictMath", gMethods, NELEM(gMethods));
184 }
185