xref: /aosp_15_r20/libcore/ojluni/src/main/native/StrictMath.c (revision 89a6322812dc8573315e60046e7959c50dad91d4)
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 <nativehelper/JNIHelp.h>
30 
31 #define NATIVE_METHOD(className, functionName, signature) \
32 { #functionName, signature, (void*)(className ## _ ## functionName) }
33 
34 
35 JNIEXPORT jdouble JNICALL
StrictMath_cos(jdouble d)36 StrictMath_cos(jdouble d)
37 {
38     return (jdouble) ieee_cos((double)d);
39 }
40 
41 JNIEXPORT jdouble JNICALL
StrictMath_sin(jdouble d)42 StrictMath_sin(jdouble d)
43 {
44     return (jdouble) ieee_sin((double)d);
45 }
46 
47 JNIEXPORT jdouble JNICALL
StrictMath_tan(jdouble d)48 StrictMath_tan(jdouble d)
49 {
50     return (jdouble) ieee_tan((double)d);
51 }
52 
53 JNIEXPORT jdouble JNICALL
StrictMath_asin(jdouble d)54 StrictMath_asin(jdouble d)
55 {
56     return (jdouble) ieee_asin((double)d);
57 }
58 
59 JNIEXPORT jdouble JNICALL
StrictMath_acos(jdouble d)60 StrictMath_acos(jdouble d)
61 {
62     return (jdouble) ieee_acos((double)d);
63 }
64 
65 JNIEXPORT jdouble JNICALL
StrictMath_atan(jdouble d)66 StrictMath_atan(jdouble d)
67 {
68     return (jdouble) ieee_atan((double)d);
69 }
70 
71 JNIEXPORT jdouble JNICALL
StrictMath_exp(jdouble d)72 StrictMath_exp(jdouble d)
73 {
74     return (jdouble) ieee_exp((double)d);
75 }
76 
77 JNIEXPORT jdouble JNICALL
StrictMath_log(jdouble d)78 StrictMath_log(jdouble d)
79 {
80     return (jdouble) ieee_log((double)d);
81 }
82 
83 JNIEXPORT jdouble JNICALL
StrictMath_log10(jdouble d)84 StrictMath_log10(jdouble d)
85 {
86     return (jdouble) ieee_log10((double)d);
87 }
88 
89 JNIEXPORT jdouble JNICALL
StrictMath_sqrt(jdouble d)90 StrictMath_sqrt(jdouble d)
91 {
92     return (jdouble) ieee_sqrt((double)d);
93 }
94 
95 JNIEXPORT jdouble JNICALL
StrictMath_cbrt(jdouble d)96 StrictMath_cbrt(jdouble d)
97 {
98     return (jdouble) ieee_cbrt((double)d);
99 }
100 
101 JNIEXPORT jdouble JNICALL
StrictMath_atan2(jdouble d1,jdouble d2)102 StrictMath_atan2(jdouble d1, jdouble d2)
103 {
104     return (jdouble) ieee_atan2((double)d1, (double)d2);
105 }
106 
107 JNIEXPORT jdouble JNICALL
StrictMath_pow(jdouble d1,jdouble d2)108 StrictMath_pow(jdouble d1, jdouble d2)
109 {
110     return (jdouble) ieee_pow((double)d1, (double)d2);
111 }
112 
113 JNIEXPORT jdouble JNICALL
StrictMath_IEEEremainder(jdouble dividend,jdouble divisor)114 StrictMath_IEEEremainder(jdouble dividend, jdouble divisor)
115 {
116     return (jdouble) ieee_remainder(dividend, divisor);
117 }
118 
119 JNIEXPORT jdouble JNICALL
StrictMath_cosh(jdouble d)120 StrictMath_cosh(jdouble d)
121 {
122     return (jdouble) ieee_cosh((double)d);
123 }
124 
125 JNIEXPORT jdouble JNICALL
StrictMath_sinh(jdouble d)126 StrictMath_sinh(jdouble d)
127 {
128     return (jdouble) ieee_sinh((double)d);
129 }
130 
131 JNIEXPORT jdouble JNICALL
StrictMath_tanh(jdouble d)132 StrictMath_tanh(jdouble d)
133 {
134     return (jdouble) ieee_tanh((double)d);
135 }
136 
137 JNIEXPORT jdouble JNICALL
StrictMath_hypot(jdouble x,jdouble y)138 StrictMath_hypot(jdouble x, jdouble y)
139 {
140     return (jdouble) ieee_hypot((double)x, (double)y);
141 }
142 
143 
144 
145 JNIEXPORT jdouble JNICALL
StrictMath_log1p(jdouble d)146 StrictMath_log1p(jdouble d)
147 {
148     return (jdouble) ieee_log1p((double)d);
149 }
150 
151 JNIEXPORT jdouble JNICALL
StrictMath_expm1(jdouble d)152 StrictMath_expm1(jdouble d)
153 {
154     return (jdouble) ieee_expm1((double)d);
155 }
156 
157 static JNINativeMethod gMethods[] = {
158   NATIVE_METHOD(StrictMath, cos, "(D)D"),
159   NATIVE_METHOD(StrictMath, sin, "(D)D"),
160   NATIVE_METHOD(StrictMath, tan, "(D)D"),
161   NATIVE_METHOD(StrictMath, asin, "(D)D"),
162   NATIVE_METHOD(StrictMath, acos, "(D)D"),
163   NATIVE_METHOD(StrictMath, atan, "(D)D"),
164   NATIVE_METHOD(StrictMath, exp, "(D)D"),
165   NATIVE_METHOD(StrictMath, log, "(D)D"),
166   NATIVE_METHOD(StrictMath, log10, "(D)D"),
167   NATIVE_METHOD(StrictMath, sqrt, "(D)D"),
168   NATIVE_METHOD(StrictMath, cbrt, "(D)D"),
169   NATIVE_METHOD(StrictMath, atan2, "(DD)D"),
170   NATIVE_METHOD(StrictMath, pow, "(DD)D"),
171   NATIVE_METHOD(StrictMath, IEEEremainder, "(DD)D"),
172   NATIVE_METHOD(StrictMath, cosh, "(D)D"),
173   NATIVE_METHOD(StrictMath, sinh, "(D)D"),
174   NATIVE_METHOD(StrictMath, tanh, "(D)D"),
175   NATIVE_METHOD(StrictMath, hypot, "(DD)D"),
176   NATIVE_METHOD(StrictMath, log1p, "(D)D"),
177   NATIVE_METHOD(StrictMath, expm1, "(D)D"),
178 };
179 
register_java_lang_StrictMath(JNIEnv * env)180 void register_java_lang_StrictMath(JNIEnv* env) {
181   jniRegisterNativeMethods(env, "java/lang/StrictMath", gMethods, NELEM(gMethods));
182 }
183