comparison src/peers/gov/nasa/jpf/vm/JPF_java_lang_Math.java @ 0:61d41facf527

initial v8 import (history reset)
author Peter Mehlitz <Peter.C.Mehlitz@nasa.gov>
date Fri, 23 Jan 2015 10:14:01 -0800
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:61d41facf527
1 /*
2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
4 * All rights reserved.
5 *
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0.
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package gov.nasa.jpf.vm;
19
20 import gov.nasa.jpf.annotation.MJI;
21 import gov.nasa.jpf.vm.MJIEnv;
22 import gov.nasa.jpf.vm.NativePeer;
23
24 /**
25 * MJI NativePeer class for java.lang.Math library abstraction
26 */
27 public class JPF_java_lang_Math extends NativePeer {
28
29 // <2do> those are here to hide their implementation from traces, not to
30 // increase performance. If we want to do that, we should probably inline
31 // their real implementation here, instead of delegating (just a compromise)
32 @MJI
33 public double abs__D__D (MJIEnv env, int clsObjRef, double a) {
34 // return Math.abs(a);
35
36 return (a <= .0) ? (.0 - a) : a;
37 }
38
39 @MJI
40 public float abs__F__F (MJIEnv env, int clsObjRef, float a) {
41 return Math.abs(a);
42 }
43
44 @MJI
45 public int abs__I__I (MJIEnv env, int clsObjRef, int a) {
46 //return Math.abs(a);
47 return (a < 0) ? -a : a; // that's probably slightly faster
48 }
49
50 @MJI
51 public long abs__J__J (MJIEnv env, int clsObjRef, long a) {
52 //return Math.abs(a);
53
54 return (a < 0) ? -a : a;
55 }
56
57 @MJI
58 public double max__DD__D (MJIEnv env, int clsObjRef, double a, double b) {
59 // that one has to handle inexact numbers, so it's probably not worth the hassle
60 // to inline it
61 return Math.max(a, b);
62 }
63
64 @MJI
65 public float max__FF__F (MJIEnv env, int clsObjRef, float a, float b) {
66 return Math.max(a, b);
67 }
68
69 @MJI
70 public int max__II__I (MJIEnv env, int clsObjRef, int a, int b) {
71 //return Math.max(a, b);
72
73 return (a >= b) ? a : b;
74 }
75
76 @MJI
77 public long max__JJ__J (MJIEnv env, int clsObjRef, long a, long b) {
78 //return Math.max(a, b);
79 return (a >= b) ? a : b;
80 }
81
82 @MJI
83 public double min__DD__D (MJIEnv env, int clsObjRef, double a, double b) {
84 return Math.min(a, b);
85 }
86
87 @MJI
88 public float min__FF__F (MJIEnv env, int clsObjRef, float a, float b) {
89 return Math.min(a, b);
90 }
91
92 @MJI
93 public int min__II__I (MJIEnv env, int clsObjRef, int a, int b) {
94 return Math.min(a, b);
95 }
96
97 @MJI
98 public long min__JJ__J (MJIEnv env, int clsObjRef, long a, long b) {
99 return Math.min(a, b);
100 }
101
102 @MJI
103 public double pow__DD__D (MJIEnv env, int clsObjRef, double a, double b) {
104 return Math.pow(a, b);
105 }
106
107 @MJI
108 public double sqrt__D__D (MJIEnv env, int clsObjRef, double a) {
109 return Math.sqrt(a);
110 }
111
112 @MJI
113 public double random____D (MJIEnv env, int clsObjRef) {
114 return Math.random();
115 }
116
117 @MJI
118 public long round__D__J (MJIEnv env, int clsObjRef, double a){
119 return Math.round(a);
120 }
121
122 @MJI
123 public double exp__D__D (MJIEnv env, int clsObjRef, double a) {
124 return Math.exp(a);
125 }
126
127 @MJI
128 public double asin__D__D (MJIEnv env, int clsObjRef, double a) {
129 return Math.asin(a);
130 }
131
132 @MJI
133 public double acos__D__D (MJIEnv env, int clsObjRef, double a) {
134 return Math.acos(a);
135 }
136
137 @MJI
138 public double atan__D__D (MJIEnv env, int clsObjRef, double a) {
139 return Math.atan(a);
140 }
141
142 @MJI
143 public double atan2__DD__D (MJIEnv env, int clsObjRef, double a, double b) {
144 return Math.atan2(a,b);
145 }
146
147 @MJI
148 public double ceil__D__D (MJIEnv env, int clsObjRef, double a) {
149 return Math.ceil(a);
150 }
151
152 @MJI
153 public double cos__D__D (MJIEnv env, int clsObjRef, double a) {
154 return Math.cos(a);
155 }
156
157 @MJI
158 public double floor__D__D (MJIEnv env, int clsObjRef, double a) {
159 return Math.floor(a);
160 }
161
162 @MJI
163 public double log10__D__D (MJIEnv env, int clsObjRef, double a) {
164 return Math.log10(a);
165 }
166
167 @MJI
168 public double log__D__D (MJIEnv env, int clsObjRef, double a) {
169 return Math.log(a);
170 }
171
172 @MJI
173 public double rint__D__D (MJIEnv env, int clsObjRef, double a) {
174 return Math.rint(a);
175 }
176
177 @MJI
178 public double sin__D__D (MJIEnv env, int clsObjRef, double a) {
179 return Math.sin(a);
180 }
181
182 @MJI
183 public double tan__D__D (MJIEnv env, int clsObjRef, double a) {
184 return Math.tan(a);
185 }
186 }