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
|
/*******************************************************************************
* Copyright (c) 2004 INRIA.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* Contributors:
* Frederic Jouault (INRIA) - initial API and implementation
*******************************************************************************/
package org.eclipse.m2m.atl.engine.vm.nativelib;
import org.eclipse.m2m.atl.engine.vm.StackFrame;
/**
* @author <a href="mailto:frederic.jouault@univ-nantes.fr">Frederic Jouault</a>
*/
public class ASMReal extends ASMNumber {
public ASMReal(double s) {
super(myType);
this.s = s;
}
public String toString() {
return "" + s;
}
public double getSymbol() {
return s;
}
public double asDouble() {
return s;
}
public boolean equals(Object o) {
return (o instanceof ASMReal) && (((ASMReal)o).s == s);
}
// Native Operations below
/* TODO: ATL VM does not support operation name overloading yet.
public static ASMReal operatorMinus(StackFrame frame, ASMReal self) {
return new ASMReal(-self.s);
}
*/
public static ASMReal operatorMinus(StackFrame frame, ASMReal self, ASMNumber o) {
return new ASMReal(self.s - o.asDouble());
}
public static ASMReal operatorPlus(StackFrame frame, ASMReal self, ASMNumber o) {
return new ASMReal(self.s + o.asDouble());
}
public static ASMReal operatorMul(StackFrame frame, ASMReal self, ASMNumber o) {
return new ASMReal(self.s * o.asDouble());
}
public static ASMReal operatorDiv(StackFrame frame, ASMReal self, ASMNumber o) {
return new ASMReal(self.s / o.asDouble());
}
public static ASMBoolean operatorEQ(StackFrame frame, ASMReal self, ASMNumber o) {
return new ASMBoolean(self.s == o.asDouble());
}
public static ASMBoolean operatorNE(StackFrame frame, ASMReal self, ASMNumber o) {
return new ASMBoolean(self.s != o.asDouble());
}
public static ASMBoolean operatorLT(StackFrame frame, ASMReal self, ASMNumber o) {
return new ASMBoolean(self.s < o.asDouble());
}
public static ASMBoolean operatorLE(StackFrame frame, ASMReal self, ASMNumber o) {
return new ASMBoolean(self.s <= o.asDouble());
}
public static ASMBoolean operatorGT(StackFrame frame, ASMReal self, ASMNumber o) {
return new ASMBoolean(self.s > o.asDouble());
}
public static ASMBoolean operatorGE(StackFrame frame, ASMReal self, ASMNumber o) {
return new ASMBoolean(self.s >= o.asDouble());
}
public static ASMString toString(StackFrame frame, ASMReal self) {
return new ASMString("" + self.s);
}
public static ASMReal abs(StackFrame frame, ASMReal self) {
return new ASMReal(Math.abs(self.s));
}
public static ASMInteger round(StackFrame frame, ASMReal self) {
return new ASMInteger((int)Math.round(self.s));
}
public static ASMInteger floor(StackFrame frame, ASMReal self) {
return new ASMInteger((int)Math.floor(self.s));
}
public static ASMReal max(StackFrame frame, ASMReal self, ASMNumber o) {
return new ASMReal(Math.max(self.s, o.asDouble()));
}
public static ASMReal min(StackFrame frame, ASMReal self, ASMNumber o) {
return new ASMReal(Math.min(self.s, o.asDouble()));
}
// Trigonometric functions, not in the OCL spec
public static ASMReal acos(StackFrame frame, ASMNumber self) {
return new ASMReal(Math.acos(self.asDouble()));
}
public static ASMReal asin(StackFrame frame, ASMNumber self) {
return new ASMReal(Math.asin(self.asDouble()));
}
public static ASMReal atan(StackFrame frame, ASMNumber self) {
return new ASMReal(Math.atan(self.asDouble()));
}
public static ASMReal cos(StackFrame frame, ASMNumber self) {
return new ASMReal(Math.cos(self.asDouble()));
}
public static ASMReal sin(StackFrame frame, ASMNumber self) {
return new ASMReal(Math.sin(self.asDouble()));
}
public static ASMReal tan(StackFrame frame, ASMNumber self) {
return new ASMReal(Math.tan(self.asDouble()));
}
public static ASMReal toDegrees(StackFrame frame, ASMNumber self) {
return new ASMReal(Math.toDegrees(self.asDouble()));
}
public static ASMReal toRadians(StackFrame frame, ASMNumber self) {
return new ASMReal(Math.toRadians(self.asDouble()));
}
// Other mathematical functions, not in the OCL spec
public static ASMReal exp(StackFrame frame, ASMNumber self) {
return new ASMReal(Math.exp(self.asDouble()));
}
public static ASMReal log(StackFrame frame, ASMNumber self) {
return new ASMReal(Math.log(self.asDouble()));
}
public static ASMReal sqrt(StackFrame frame, ASMNumber self) {
return new ASMReal(Math.sqrt(self.asDouble()));
}
private double s;
}
|