CACAO
java_lang_Math.cpp
Go to the documentation of this file.
1 /* src/native/vm/cldc1.1/java_lang_Math.cpp
2 
3  Copyright (C) 2006-2013
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2, or (at
11  your option) any later version.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 
23 */
24 
25 
26 #include "config.h"
27 
28 #include <stdint.h>
29 
30 #include "fdlibm/fdlibm.h"
31 
32 #include "native/jni.hpp"
33 #include "native/native.hpp"
34 
35 #if defined(ENABLE_JNI_HEADERS)
36 # include "native/include/java_lang_Math.h"
37 #endif
38 
39 #include "vm/vm.hpp"
40 
41 
42 // Native functions are exported as C functions.
43 extern "C" {
44 
45 /*
46  * Class: java/lang/Math
47  * Method: ceil
48  * Signature: (D)D
49  */
50 JNIEXPORT jdouble JNICALL Java_java_lang_Math_ceil(JNIEnv *env, jclass clazz, jdouble a)
51 {
52  return ceil(a);
53 }
54 
55 
56 /*
57  * Class: java/lang/Math
58  * Method: cos
59  * Signature: (D)D
60  */
61 JNIEXPORT jdouble JNICALL Java_java_lang_Math_cos(JNIEnv *env, jclass clazz, jdouble a)
62 {
63  return cos(a);
64 }
65 
66 
67 /*
68  * Class: java/lang/Math
69  * Method: floor
70  * Signature: (D)D
71  */
72 JNIEXPORT jdouble JNICALL Java_java_lang_Math_floor(JNIEnv *env, jclass clazz, jdouble a)
73 {
74  return floor(a);
75 }
76 
77 
78 /*
79  * Class: java/lang/Math
80  * Method: sin
81  * Signature: (D)D
82  */
83 JNIEXPORT jdouble JNICALL Java_java_lang_Math_sin(JNIEnv *env, jclass clazz, jdouble a)
84 {
85  return sin(a);
86 }
87 
88 
89 /*
90  * Class: java/lang/Math
91  * Method: sqrt
92  * Signature: (D)D
93  */
94 JNIEXPORT jdouble JNICALL Java_java_lang_Math_sqrt(JNIEnv *env, jclass clazz, jdouble a)
95 {
96  return sqrt(a);
97 }
98 
99 
100 /*
101  * Class: java/lang/Math
102  * Method: tan
103  * Signature: (D)D
104  */
105 JNIEXPORT jdouble JNICALL Java_java_lang_Math_tan(JNIEnv *env, jclass clazz, jdouble a)
106 {
107  return tan(a);
108 }
109 
110 } // extern "C"
111 
112 
113 /* native methods implemented by this file ************************************/
114 
115 static JNINativeMethod methods[] = {
116  { (char*) "ceil", (char*) "(D)D", (void*) (uintptr_t) &Java_java_lang_Math_ceil },
117  { (char*) "cos", (char*) "(D)D", (void*) (uintptr_t) &Java_java_lang_Math_cos },
118  { (char*) "floor", (char*) "(D)D", (void*) (uintptr_t) &Java_java_lang_Math_floor },
119  { (char*) "sin", (char*) "(D)D", (void*) (uintptr_t) &Java_java_lang_Math_sin },
120  { (char*) "sqrt", (char*) "(D)D", (void*) (uintptr_t) &Java_java_lang_Math_sqrt },
121  { (char*) "tan", (char*) "(D)D", (void*) (uintptr_t) &Java_java_lang_Math_tan },
122 };
123 
124 
125 /* _Jv_java_lang_Math_init *****************************************************
126 
127  Register native functions.
128 
129 *******************************************************************************/
130 
132 {
133  Utf8String u = Utf8String::from_utf8("java/lang/Math");
134 
137 }
138 
139 
140 /*
141  * These are local overrides for various environment variables in Emacs.
142  * Please do not remove this and leave it at the end of the file, where
143  * Emacs will automagically detect them.
144  * ---------------------------------------------------------------------
145  * Local variables:
146  * mode: c++
147  * indent-tabs-mode: t
148  * c-basic-offset: 4
149  * tab-width: 4
150  * End:
151  * vim:noexpandtab:sw=4:ts=4:
152  */
static JNINativeMethod methods[]
Table containing all native methods registered with the VM.
Definition: native.hpp:132
NativeMethods & get_nativemethods()
Definition: vm.hpp:128
void register_methods(Utf8String classname, const JNINativeMethod *methods, size_t count)
Register native methods with the VM.
Definition: native.cpp:242
void _Jv_java_lang_Math_init(void)
_Jv_JNIEnv JNIEnv
Definition: jni.hpp:112
#define NATIVE_METHODS_COUNT
Definition: native.hpp:45
JNIEXPORT jdouble JNICALL Java_java_lang_Math_sin(JNIEnv *env, jclass clazz, jdouble a)
JNIEXPORT jdouble JNICALL Java_java_lang_Math_tan(JNIEnv *env, jclass clazz, jdouble a)
JNIEXPORT jdouble JNICALL Java_java_lang_Math_cos(JNIEnv *env, jclass clazz, jdouble a)
JNIEXPORT jdouble JNICALL Java_java_lang_Math_floor(JNIEnv *env, jclass clazz, jdouble a)
static Utf8String from_utf8(const char *, size_t)
Definition: utf8.cpp:335
JNIEXPORT jdouble JNICALL Java_java_lang_Math_ceil(JNIEnv *env, jclass clazz, jdouble a)
static VM * get_current()
Definition: vm.hpp:99
JNIEXPORT jdouble JNICALL Java_java_lang_Math_sqrt(JNIEnv *env, jclass clazz, jdouble a)