summaryrefslogtreecommitdiffstats
path: root/luni/src/main/native/java_lang_Math.cpp
blob: 7fdce6fc5f074eeb8ceb6e012c3b88ffc3e89c9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
 * Copyright 2006 The Android Open Source Project 
 *
 * Native functions for java.lang.Math.
 */
#include "jni.h"
#include "JNIHelp.h"

#include <stdlib.h>
#include <math.h>

/* native public static double sin(double a); */
static jdouble jsin(JNIEnv*, jclass, jdouble a)
{
    return sin(a);
}

/* native public static double cos(double a); */
static jdouble jcos(JNIEnv*, jclass, jdouble a)
{
    return cos(a);
}

/* native public static double tan(double a); */
static jdouble jtan(JNIEnv*, jclass, jdouble a)
{
    return tan(a);
}

/* native public static double asin(double a); */
static jdouble jasin(JNIEnv*, jclass, jdouble a)
{
    return asin(a);
}

/* native public static double acos(double a); */
static jdouble jacos(JNIEnv*, jclass, jdouble a)
{
    return acos(a);
}

/* native public static double atan(double a); */
static jdouble jatan(JNIEnv*, jclass, jdouble a)
{
    return atan(a);
}

/* native public static double exp(double a); */
static jdouble jexp(JNIEnv*, jclass, jdouble a)
{
    return exp(a);
}

/* native public static double log(double a); */
static jdouble jlog(JNIEnv*, jclass, jdouble a)
{
    return log(a);
}

/* native public static double sqrt(double a); */
static jdouble jsqrt(JNIEnv*, jclass, jdouble a)
{
    return sqrt(a);
}

/* native public static double IEEEremainder(double a, double b); */
static jdouble jieee_remainder(JNIEnv*, jclass, jdouble a, jdouble b)
{
    return remainder(a, b);
}

/* native public static double floor(double a); */
static jdouble jfloor(JNIEnv*, jclass, jdouble a)
{
    return floor(a);
}

/* native public static double ceil(double a); */
static jdouble jceil(JNIEnv*, jclass, jdouble a)
{
    return ceil(a);
}

/* native public static double rint(double a); */
static jdouble jrint(JNIEnv*, jclass, jdouble a)
{
    return rint(a);
}

/* native public static double atan2(double a, double b); */
static jdouble jatan2(JNIEnv*, jclass, jdouble a, jdouble b)
{
    return atan2(a, b);
}

/* native public static double pow(double a, double b); */
static jdouble jpow(JNIEnv*, jclass, jdouble a, jdouble b)
{
    return pow(a, b);
}

/* native public static double sinh(double a); */
static jdouble jsinh(JNIEnv*, jclass, jdouble a)
{
    return sinh(a);
}

/* native public static double tanh(double a); */
static jdouble jtanh(JNIEnv*, jclass, jdouble a)
{
    return tanh(a);
}

/* native public static double cosh(double a); */
static jdouble jcosh(JNIEnv*, jclass, jdouble a)
{
    return cosh(a);
}

/* native public static double log10(double a); */
static jdouble jlog10(JNIEnv*, jclass, jdouble a)
{
    return log10(a);
}

/* native public static double cbrt(double a); */
static jdouble jcbrt(JNIEnv*, jclass, jdouble a)
{
    return cbrt(a);
}

/* native public static double expm1(double a); */
static jdouble jexpm1(JNIEnv*, jclass, jdouble a)
{
    return expm1(a);
}

/* native public static double hypot(double a, double b); */
static jdouble jhypot(JNIEnv*, jclass, jdouble a, jdouble b)
{
    return hypot(a, b);
}

/* native public static double log1p(double a); */
static jdouble jlog1p(JNIEnv*, jclass, jdouble a)
{
    return log1p(a);
}

/* native public static double nextafter(double a, double b); */
static jdouble jnextafter(JNIEnv*, jclass, jdouble a, jdouble b)
{
    return nextafter(a, b);
}

/* native public static float nextafterf(float a, float b); */
static jfloat jnextafterf(JNIEnv*, jclass, jfloat a, jfloat b)
{
    return nextafterf(a, b);
}

static jdouble copySign(JNIEnv*, jclass, jdouble a, jdouble b) {
    // Our StrictMath.copySign delegates to Math.copySign, so we need to treat NaN as positive.
    return copysign(a, isnan(b) ? 1.0 : b);
}

static jfloat copySign_f(JNIEnv*, jclass, jfloat a, jfloat b) {
    // Our StrictMath.copySign delegates to Math.copySign, so we need to treat NaN as positive.
    return copysignf(a, isnan(b) ? 1.0 : b);
}

static JNINativeMethod gMethods[] = {
    { "IEEEremainder", "(DD)D", (void*)jieee_remainder },
    { "acos",          "(D)D",  (void*)jacos },
    { "asin",          "(D)D",  (void*)jasin },
    { "atan",          "(D)D",  (void*)jatan },
    { "atan2",         "(DD)D", (void*)jatan2 },
    { "cbrt",          "(D)D",  (void*)jcbrt },
    { "ceil",          "(D)D",  (void*)jceil },
    { "copySign",      "(DD)D", (void*)copySign },
    { "copySign",      "(FF)F", (void*)copySign_f },
    { "cos",           "(D)D",  (void*)jcos },
    { "cosh",          "(D)D",  (void*)jcosh },
    { "exp",           "(D)D",  (void*)jexp },
    { "expm1",         "(D)D",  (void*)jexpm1 },
    { "floor",         "(D)D",  (void*)jfloor },
    { "hypot",         "(DD)D", (void*)jhypot },
    { "log",           "(D)D",  (void*)jlog },
    { "log10",         "(D)D",  (void*)jlog10 },
    { "log1p",         "(D)D",  (void*)jlog1p },
    { "nextafter",     "(DD)D", (void*)jnextafter },
    { "nextafterf",    "(FF)F", (void*)jnextafterf },
    { "pow",           "(DD)D", (void*)jpow },
    { "rint",          "(D)D",  (void*)jrint },
    { "sin",           "(D)D",  (void*)jsin },
    { "sinh",          "(D)D",  (void*)jsinh },
    { "sqrt",          "(D)D",  (void*)jsqrt },
    { "tan",           "(D)D",  (void*)jtan },
    { "tanh",          "(D)D",  (void*)jtanh },
};

int register_java_lang_Math(JNIEnv* env) {
    return jniRegisterNativeMethods(env, "java/lang/Math", gMethods, NELEM(gMethods));
}