2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
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
10 * http://www.apache.org/licenses/LICENSE-2.0.
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.
18 package gov.nasa.jpf.vm;
20 import gov.nasa.jpf.annotation.MJI;
21 import gov.nasa.jpf.vm.MJIEnv;
22 import gov.nasa.jpf.vm.NativePeer;
25 * MJI NativePeer class for java.lang.Math library abstraction
27 public class JPF_java_lang_Math extends NativePeer {
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)
33 public double abs__D__D (MJIEnv env, int clsObjRef, double a) {
34 // return Math.abs(a);
36 return (a <= .0) ? (.0 - a) : a;
40 public float abs__F__F (MJIEnv env, int clsObjRef, float a) {
45 public int abs__I__I (MJIEnv env, int clsObjRef, int a) {
47 return (a < 0) ? -a : a; // that's probably slightly faster
51 public long abs__J__J (MJIEnv env, int clsObjRef, long a) {
54 return (a < 0) ? -a : a;
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
61 return Math.max(a, b);
65 public float max__FF__F (MJIEnv env, int clsObjRef, float a, float b) {
66 return Math.max(a, b);
70 public int max__II__I (MJIEnv env, int clsObjRef, int a, int b) {
71 //return Math.max(a, b);
73 return (a >= b) ? a : b;
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;
83 public double min__DD__D (MJIEnv env, int clsObjRef, double a, double b) {
84 return Math.min(a, b);
88 public float min__FF__F (MJIEnv env, int clsObjRef, float a, float b) {
89 return Math.min(a, b);
93 public int min__II__I (MJIEnv env, int clsObjRef, int a, int b) {
94 return Math.min(a, b);
98 public long min__JJ__J (MJIEnv env, int clsObjRef, long a, long b) {
99 return Math.min(a, b);
103 public double pow__DD__D (MJIEnv env, int clsObjRef, double a, double b) {
104 return Math.pow(a, b);
108 public double sqrt__D__D (MJIEnv env, int clsObjRef, double a) {
113 public double random____D (MJIEnv env, int clsObjRef) {
114 return Math.random();
118 public long round__D__J (MJIEnv env, int clsObjRef, double a){
119 return Math.round(a);
123 public double exp__D__D (MJIEnv env, int clsObjRef, double a) {
128 public double asin__D__D (MJIEnv env, int clsObjRef, double a) {
133 public double acos__D__D (MJIEnv env, int clsObjRef, double a) {
138 public double atan__D__D (MJIEnv env, int clsObjRef, double a) {
143 public double atan2__DD__D (MJIEnv env, int clsObjRef, double a, double b) {
144 return Math.atan2(a,b);
148 public double ceil__D__D (MJIEnv env, int clsObjRef, double a) {
153 public double cos__D__D (MJIEnv env, int clsObjRef, double a) {
158 public double floor__D__D (MJIEnv env, int clsObjRef, double a) {
159 return Math.floor(a);
163 public double log10__D__D (MJIEnv env, int clsObjRef, double a) {
164 return Math.log10(a);
168 public double log__D__D (MJIEnv env, int clsObjRef, double a) {
173 public double rint__D__D (MJIEnv env, int clsObjRef, double a) {
178 public double sin__D__D (MJIEnv env, int clsObjRef, double a) {
183 public double tan__D__D (MJIEnv env, int clsObjRef, double a) {