1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.zel.instr.var;
20
21 import net.sf.zel.instr.*;
22 import net.sf.zel.nr.ExtendedNumber;
23 import net.sf.zel.nr.OperableBigInteger;
24 import net.sf.zel.nr.OperableDouble;
25 import net.sf.zel.nr.OperableInteger;
26 import net.sf.zel.nr.OperableLong;
27 import net.sf.zel.nr.OperableNumber;
28 import net.sf.zel.vm.*;
29
30
31
32
33
34 public class INT extends Instruction
35 {
36
37
38
39
40 public static final Instruction instance = new INT();
41
42
43 private static final long serialVersionUID = 5154431044890636019L;
44
45
46 private INT(){};
47
48
49
50
51
52
53
54 public final void execute(ExecutionContext context) throws ZExecutionException
55 {
56 OperableNumber val = (OperableNumber) context.popSyncStackVal();
57 context.stack.pop();
58 if (val.getType() == ExtendedNumber.Type.INTEGER )
59 context.stack.push(val);
60 else
61 {
62 if (val.compareTo(new OperableDouble(Double.valueOf((double)Integer.MAX_VALUE))) <= 0)
63 context.stack.push(new OperableInteger(val.intValue()));
64 else if (val.compareTo(new OperableDouble(Double.valueOf((double)Long.MAX_VALUE))) <= 0)
65 context.stack.push(new OperableLong(val.longValue()));
66 else
67 context.stack.push(new OperableBigInteger(val.bigIntegerValue()));
68 }
69 context.ip++;
70
71
72 }
73 }