Skip to content

Commit 924177e

Browse files
author
linzhijun
committed
使用 decimal 代替 double
1 parent a9aa131 commit 924177e

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

csharp/ToolGood.Algorithm2/Internals/MathVisitor.cs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ private static Operand Compare(Operand op1, Operand op2, string type)
275275
var t1 = op1.NumberValue;
276276
var t2 = op2.NumberValue;
277277

278-
var r = Math.Round(t1 - t2, 10, MidpointRounding.AwayFromZero);
278+
var r = t1 - t2;
279+
//var r = Math.Round(t1 - t2, 10, MidpointRounding.AwayFromZero);
279280
if (type.Length == 1) {
280281
if (CharUtil.Equals(type, '<')) {
281282
return Operand.Create(r < 0);
@@ -296,7 +297,8 @@ private static Operand Compare(Operand op1, Operand op2, string type)
296297

297298
private static int Compare(decimal t1, decimal t2)
298299
{
299-
var b = Math.Round(t1 - t2, 12, MidpointRounding.AwayFromZero);
300+
var b = t1 - t2;
301+
//var b = Math.Round(t1 - t2, 12, MidpointRounding.AwayFromZero);
300302
if (b == 0) {
301303
return 0;
302304
} else if (b > 0) {
@@ -2863,11 +2865,14 @@ public virtual Operand VisitWEIBULL_fun(mathParser.WEIBULL_funContext context)
28632865
private static int F_base_countif(List<decimal> dbs, decimal d)
28642866
{
28652867
int count = 0;
2866-
d = Math.Round(d, 12, MidpointRounding.AwayFromZero);
2868+
//d = Math.Round(d, 12, MidpointRounding.AwayFromZero);
28672869
foreach (var item in dbs) {
2868-
if (Math.Round(item, 12, MidpointRounding.AwayFromZero) == d) {
2870+
if (item==d) {
28692871
count++;
28702872
}
2873+
//if (Math.Round(item, 12, MidpointRounding.AwayFromZero) == d) {
2874+
// count++;
2875+
//}
28712876
}
28722877
return count;
28732878
}
@@ -2902,17 +2907,23 @@ private static decimal F_base_sumif(List<decimal> dbs, string s, List<decimal> s
29022907
private static bool F_base_compare(decimal a, decimal b, string ss)
29032908
{
29042909
if (CharUtil.Equals(ss, '<')) {
2905-
return Math.Round(a - b, 12, MidpointRounding.AwayFromZero) < 0;
2910+
return a < b;
2911+
//return Math.Round(a - b, 12, MidpointRounding.AwayFromZero) < 0;
29062912
} else if (CharUtil.Equals(ss, "<=")) {
2907-
return Math.Round(a - b, 12, MidpointRounding.AwayFromZero) <= 0;
2913+
return a <= b;
2914+
//return Math.Round(a - b, 12, MidpointRounding.AwayFromZero) <= 0;
29082915
} else if (CharUtil.Equals(ss, '>')) {
2909-
return Math.Round(a - b, 12, MidpointRounding.AwayFromZero) > 0;
2916+
return a > b;
2917+
//return Math.Round(a - b, 12, MidpointRounding.AwayFromZero) > 0;
29102918
} else if (CharUtil.Equals(ss, ">=")) {
2911-
return Math.Round(a - b, 12, MidpointRounding.AwayFromZero) >= 0;
2919+
return (a >= b);
2920+
//return Math.Round(a - b, 12, MidpointRounding.AwayFromZero) >= 0;
29122921
} else if (CharUtil.Equals(ss, "=", "==", "===")) {
2913-
return Math.Round(a - b, 12, MidpointRounding.AwayFromZero) == 0;
2922+
return a==b;
2923+
//return Math.Round(a - b, 12, MidpointRounding.AwayFromZero) == 0;
29142924
}
2915-
return Math.Round(a - b, 12, MidpointRounding.AwayFromZero) != 0;
2925+
return a != b;
2926+
//return Math.Round(a - b, 12, MidpointRounding.AwayFromZero) != 0;
29162927
}
29172928

29182929
private bool F_base_GetList(List<Operand> args, List<decimal> list)

0 commit comments

Comments
 (0)