1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package io.github.prolobjectlink.prolog.jlog;
23
24 import ubc.cs.JLog.Foundation.jEquivalenceMapping;
25 import ubc.cs.JLog.Foundation.jUnifiedVector;
26 import ubc.cs.JLog.Foundation.jVariableRegistry;
27 import ubc.cs.JLog.Foundation.jVariableVector;
28 import ubc.cs.JLog.Terms.iPredicate;
29 import ubc.cs.JLog.Terms.jInteger;
30 import ubc.cs.JLog.Terms.jTerm;
31 import ubc.cs.JLog.Terms.jVariable;
32
33
34
35
36
37
38 class jDouble extends jTerm {
39
40 private double value;
41
42 jDouble(double v) {
43 value = v;
44 type = TYPE_REAL;
45 }
46
47 @Override
48 public String getName() {
49 return String.valueOf(value);
50 }
51
52 public double getRealValue() {
53 return value;
54 }
55
56 protected int compare(jTerm term, boolean firstCall, boolean varEqual) {
57 jTerm t = term.getTerm();
58
59 if (t instanceof jVariable)
60 return GREATER_THAN;
61
62 if (t instanceof jDouble) {
63 double f = ((jDouble) t).getRealValue();
64
65 if (value < f)
66 return LESS_THAN;
67 else if (value > f)
68 return GREATER_THAN;
69 else
70 return EQUAL;
71 }
72
73 if (t instanceof jInteger)
74 return LESS_THAN;
75
76 if (t instanceof iPredicate)
77 return LESS_THAN;
78
79 return (firstCall ? -t.compare(this, varEqual) : EQUAL);
80 }
81
82 public boolean equivalence(jTerm term, jEquivalenceMapping v) {
83 jTerm t = term.getTerm();
84
85
86 if (this == t)
87 return true;
88
89 if (type != t.type)
90 return false;
91
92
93
94
95 return (value == ((jDouble) t).value);
96 }
97
98 public boolean unify(jTerm term, jUnifiedVector v) {
99
100 if (term.type == TYPE_VARIABLE)
101 return term.unify(this, v);
102
103
104 if (this == term)
105 return true;
106
107 if (type != term.type)
108 return false;
109
110
111
112
113 return (value == ((jDouble) term).value);
114 }
115
116 public void registerVariables(jVariableVector v) {
117
118 }
119
120 public void enumerateVariables(jVariableVector v, boolean all) {
121
122 }
123
124 public jTerm duplicate(jVariable[] vars) {
125 return this;
126 }
127
128 public jTerm copy(jVariableRegistry vars) {
129 return this;
130 }
131
132 public String toString(boolean usename) {
133 return String.valueOf(value);
134 }
135 }