• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /*
2   * Copyright (C) 2006 The Android Open Source Project
3   *
4   * Licensed under the Apache License, Version 2.0 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   *
8   *      http://www.apache.org/licenses/LICENSE-2.0
9   *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  #define LOG_TAG "StrictMath"
18  
19  #include "../../external/fdlibm/fdlibm.h"
20  
21  #include "jni.h"
22  #include "JNIHelp.h"
23  #include "JniConstants.h"
24  
StrictMath_sin(JNIEnv *,jclass,jdouble a)25  static jdouble StrictMath_sin(JNIEnv*, jclass, jdouble a) {
26      return ieee_sin(a);
27  }
28  
StrictMath_cos(JNIEnv *,jclass,jdouble a)29  static jdouble StrictMath_cos(JNIEnv*, jclass, jdouble a) {
30      return ieee_cos(a);
31  }
32  
StrictMath_tan(JNIEnv *,jclass,jdouble a)33  static jdouble StrictMath_tan(JNIEnv*, jclass, jdouble a) {
34      return ieee_tan(a);
35  }
36  
StrictMath_asin(JNIEnv *,jclass,jdouble a)37  static jdouble StrictMath_asin(JNIEnv*, jclass, jdouble a) {
38      return ieee_asin(a);
39  }
40  
StrictMath_acos(JNIEnv *,jclass,jdouble a)41  static jdouble StrictMath_acos(JNIEnv*, jclass, jdouble a) {
42      return ieee_acos(a);
43  }
44  
StrictMath_atan(JNIEnv *,jclass,jdouble a)45  static jdouble StrictMath_atan(JNIEnv*, jclass, jdouble a) {
46      return ieee_atan(a);
47  }
48  
StrictMath_exp(JNIEnv *,jclass,jdouble a)49  static jdouble StrictMath_exp(JNIEnv*, jclass, jdouble a) {
50      return ieee_exp(a);
51  }
52  
StrictMath_log(JNIEnv *,jclass,jdouble a)53  static jdouble StrictMath_log(JNIEnv*, jclass, jdouble a) {
54      return ieee_log(a);
55  }
56  
StrictMath_sqrt(JNIEnv *,jclass,jdouble a)57  static jdouble StrictMath_sqrt(JNIEnv*, jclass, jdouble a) {
58      return ieee_sqrt(a);
59  }
60  
StrictMath_IEEEremainder(JNIEnv *,jclass,jdouble a,jdouble b)61  static jdouble StrictMath_IEEEremainder(JNIEnv*, jclass, jdouble a, jdouble b) {
62      return ieee_remainder(a, b);
63  }
64  
StrictMath_floor(JNIEnv *,jclass,jdouble a)65  static jdouble StrictMath_floor(JNIEnv*, jclass, jdouble a) {
66      return ieee_floor(a);
67  }
68  
StrictMath_ceil(JNIEnv *,jclass,jdouble a)69  static jdouble StrictMath_ceil(JNIEnv*, jclass, jdouble a) {
70      return ieee_ceil(a);
71  }
72  
StrictMath_rint(JNIEnv *,jclass,jdouble a)73  static jdouble StrictMath_rint(JNIEnv*, jclass, jdouble a) {
74      return ieee_rint(a);
75  }
76  
StrictMath_atan2(JNIEnv *,jclass,jdouble a,jdouble b)77  static jdouble StrictMath_atan2(JNIEnv*, jclass, jdouble a, jdouble b) {
78      return ieee_atan2(a, b);
79  }
80  
StrictMath_pow(JNIEnv *,jclass,jdouble a,jdouble b)81  static jdouble StrictMath_pow(JNIEnv*, jclass, jdouble a, jdouble b) {
82      return ieee_pow(a,b);
83  }
84  
StrictMath_sinh(JNIEnv *,jclass,jdouble a)85  static jdouble StrictMath_sinh(JNIEnv*, jclass, jdouble a) {
86      return ieee_sinh(a);
87  }
88  
StrictMath_tanh(JNIEnv *,jclass,jdouble a)89  static jdouble StrictMath_tanh(JNIEnv*, jclass, jdouble a) {
90      return ieee_tanh(a);
91  }
92  
StrictMath_cosh(JNIEnv *,jclass,jdouble a)93  static jdouble StrictMath_cosh(JNIEnv*, jclass, jdouble a) {
94      return ieee_cosh(a);
95  }
96  
StrictMath_log10(JNIEnv *,jclass,jdouble a)97  static jdouble StrictMath_log10(JNIEnv*, jclass, jdouble a) {
98      return ieee_log10(a);
99  }
100  
StrictMath_cbrt(JNIEnv *,jclass,jdouble a)101  static jdouble StrictMath_cbrt(JNIEnv*, jclass, jdouble a) {
102      return ieee_cbrt(a);
103  }
104  
StrictMath_expm1(JNIEnv *,jclass,jdouble a)105  static jdouble StrictMath_expm1(JNIEnv*, jclass, jdouble a) {
106      return ieee_expm1(a);
107  }
108  
StrictMath_hypot(JNIEnv *,jclass,jdouble a,jdouble b)109  static jdouble StrictMath_hypot(JNIEnv*, jclass, jdouble a, jdouble b) {
110      return ieee_hypot(a, b);
111  }
112  
StrictMath_log1p(JNIEnv *,jclass,jdouble a)113  static jdouble StrictMath_log1p(JNIEnv*, jclass, jdouble a) {
114      return ieee_log1p(a);
115  }
116  
StrictMath_nextafter(JNIEnv *,jclass,jdouble a,jdouble b)117  static jdouble StrictMath_nextafter(JNIEnv*, jclass, jdouble a, jdouble b) {
118      return ieee_nextafter(a, b);
119  }
120  
121  extern jint Float_floatToRawIntBits(JNIEnv*, jclass, jfloat);
122  extern jfloat Float_intBitsToFloat(JNIEnv*, jclass, jint val);
123  
124  // TODO: we should make Float.floatToRawBits and Float.intBitsToFloat intrinsics, and move
125  // this kind of code into Java.
StrictMath_nextafterf(JNIEnv *,jclass,jfloat arg1,jfloat arg2)126  static jfloat StrictMath_nextafterf(JNIEnv*, jclass, jfloat arg1, jfloat arg2) {
127      jint hx = Float_floatToRawIntBits(NULL, NULL, arg1);
128      jint hy = Float_floatToRawIntBits(NULL, NULL, arg2);
129  
130      if (!(hx & 0x7fffffff)) { /* arg1 == 0 */
131          return Float_intBitsToFloat(NULL, NULL, (hy & 0x80000000) | 0x1);
132      }
133  
134      if ((hx > 0) ^ (hx > hy)) { /* |arg1| < |arg2| */
135          hx += 1;
136      } else {
137          hx -= 1;
138      }
139      return Float_intBitsToFloat(NULL, NULL, hx);
140  }
141  
142  static JNINativeMethod gMethods[] = {
143      NATIVE_METHOD(StrictMath, IEEEremainder, "(DD)D"),
144      NATIVE_METHOD(StrictMath, acos, "(D)D"),
145      NATIVE_METHOD(StrictMath, asin, "(D)D"),
146      NATIVE_METHOD(StrictMath, atan, "(D)D"),
147      NATIVE_METHOD(StrictMath, atan2, "(DD)D"),
148      NATIVE_METHOD(StrictMath, cbrt, "(D)D"),
149      NATIVE_METHOD(StrictMath, ceil, "(D)D"),
150      NATIVE_METHOD(StrictMath, cos, "(D)D"),
151      NATIVE_METHOD(StrictMath, cosh, "(D)D"),
152      NATIVE_METHOD(StrictMath, exp, "(D)D"),
153      NATIVE_METHOD(StrictMath, expm1, "(D)D"),
154      NATIVE_METHOD(StrictMath, floor, "(D)D"),
155      NATIVE_METHOD(StrictMath, hypot, "(DD)D"),
156      NATIVE_METHOD(StrictMath, log, "(D)D"),
157      NATIVE_METHOD(StrictMath, log10, "(D)D"),
158      NATIVE_METHOD(StrictMath, log1p, "(D)D"),
159      NATIVE_METHOD(StrictMath, nextafter, "(DD)D"),
160      NATIVE_METHOD(StrictMath, nextafterf, "(FF)F"),
161      NATIVE_METHOD(StrictMath, pow, "(DD)D"),
162      NATIVE_METHOD(StrictMath, rint, "(D)D"),
163      NATIVE_METHOD(StrictMath, sin, "(D)D"),
164      NATIVE_METHOD(StrictMath, sinh, "(D)D"),
165      NATIVE_METHOD(StrictMath, sqrt, "(D)D"),
166      NATIVE_METHOD(StrictMath, tan, "(D)D"),
167      NATIVE_METHOD(StrictMath, tanh, "(D)D"),
168  };
169  
register_java_lang_StrictMath(JNIEnv * env)170  int register_java_lang_StrictMath(JNIEnv* env) {
171      return jniRegisterNativeMethods(env, "java/lang/StrictMath", gMethods, NELEM(gMethods));
172  }
173