Skip to content

Commit f5ec3f5

Browse files
nokiaMSgithubgxll
authored andcommitted
[fix][libexpr] Fix issue about decimal eq and ne.
1 parent 6b0a117 commit f5ec3f5

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

src/types/decimal/decimal.h

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,14 @@ class Decimal {
219219
* @return
220220
*/
221221
bool operator==(const Decimal &dec) const {
222-
return v == dec.getMpf();
222+
const mpf_class& mpf1 = mpf_class(toString());
223+
const mpf_class& mpf2 = mpf_class(dec.toString());
224+
225+
int ret = cmp(mpf1, mpf2);
226+
if(ret == 0) {
227+
return true;
228+
}
229+
return false;
223230
}
224231

225232
/**
@@ -228,7 +235,7 @@ class Decimal {
228235
* @return
229236
*/
230237
bool operator!=(const Decimal &dec) const {
231-
return v != dec.getMpf();
238+
return !(*this == dec);
232239
}
233240

234241
/**
@@ -237,7 +244,14 @@ class Decimal {
237244
* @return
238245
*/
239246
bool operator<(const Decimal &dec) const {
240-
return v < dec.getMpf();
247+
const mpf_class& mpf1 = mpf_class(toString());
248+
const mpf_class& mpf2 = mpf_class(dec.toString());
249+
250+
int ret = cmp(mpf1, mpf2);
251+
if(ret < 0) {
252+
return true;
253+
}
254+
return false;
241255
}
242256

243257
/**
@@ -246,7 +260,14 @@ class Decimal {
246260
* @return
247261
*/
248262
bool operator<=(const Decimal &dec) const {
249-
return v <= dec.getMpf();
263+
const mpf_class& mpf1 = mpf_class(toString());
264+
const mpf_class& mpf2 = mpf_class(dec.toString());
265+
266+
int ret = cmp(mpf1, mpf2);
267+
if(ret <= 0) {
268+
return true;
269+
}
270+
return false;
250271
}
251272

252273
/**
@@ -255,7 +276,14 @@ class Decimal {
255276
* @return
256277
*/
257278
bool operator>(const Decimal &dec) const {
258-
return v > dec.getMpf();;
279+
const mpf_class& mpf1 = mpf_class(toString());
280+
const mpf_class& mpf2 = mpf_class(dec.toString());
281+
282+
int ret = cmp(mpf1, mpf2);
283+
if(ret > 0) {
284+
return true;
285+
}
286+
return false;
259287
}
260288

261289
/**
@@ -264,7 +292,14 @@ class Decimal {
264292
* @return
265293
*/
266294
bool operator>=(const Decimal &dec) const {
267-
return v >= dec.getMpf();
295+
const mpf_class& mpf1 = mpf_class(toString());
296+
const mpf_class& mpf2 = mpf_class(dec.toString());
297+
298+
int ret = cmp(mpf1, mpf2);
299+
if(ret >= 0) {
300+
return true;
301+
}
302+
return false;
268303
}
269304

270305
/**

0 commit comments

Comments
 (0)