Skip to content

Commit a9aa131

Browse files
author
linzhijun
committed
修改 decimal 代替 double
1 parent dd359b9 commit a9aa131

File tree

14 files changed

+483
-483
lines changed

14 files changed

+483
-483
lines changed

csharp/ToolGood.Algorithm2.Test/AlgorithmEngine/AlgorithmEngineTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ public void Test()
4444

4545

4646
var e = engine.TryEvaluate("e", 0.0);
47-
Assert.AreEqual(Math.E, e);
47+
Assert.AreEqual(Math.E, e,10);
4848
e = engine.TryEvaluate("pi", 0.0);
49-
Assert.AreEqual(Math.PI, e);
49+
Assert.AreEqual(Math.PI, e,10);
5050

5151
var b = engine.TryEvaluate("true", true);
5252
Assert.AreEqual(true, b);
@@ -60,9 +60,9 @@ public void Test()
6060
Assert.AreEqual(2, b1);
6161

6262
var b2 = engine.TryEvaluate("pi*4", 0.0);
63-
Assert.AreEqual(Math.PI * 4, b2);
63+
Assert.AreEqual(Math.PI * 4, b2,10);
6464
b2 = engine.TryEvaluate("e*4", 0.0);
65-
Assert.AreEqual(Math.E * 4, b2);
65+
Assert.AreEqual(Math.E * 4, b2,10);
6666

6767
var s = engine.TryEvaluate("'aa'&'bb'", "");
6868
Assert.AreEqual("aabb", s);
@@ -246,7 +246,7 @@ public void Cylinder_Test()
246246
t = c.TryEvaluate("['半径']*[半径]*pi()*[高]", 0.0); //圆的体积
247247

248248
t = c.TryEvaluate("求面积(10)", 0.0); //圆的体积
249-
Assert.AreEqual(10 * 10 * Math.PI, t);
249+
Assert.AreEqual(10 * 10 * Math.PI, t,10);
250250

251251

252252

@@ -267,7 +267,7 @@ public void Test5555()
267267
{
268268
Cylinder c = new Cylinder(3, 10);
269269
String t = c.GetSimplifiedFormula("[半径]*[半径]*pi()"); // 圆底面积
270-
Assert.AreEqual("3 * 3 * 3.141592653589793", t);
270+
Assert.AreEqual("3 * 3 * 3.14159265358979", t);
271271

272272
String t2 = c.GetSimplifiedFormula("半径*if(半径>2,1,3)");
273273
Assert.AreEqual("3 * 1", t2);

csharp/ToolGood.Algorithm2.Test/AlgorithmEngine/AlgorithmEngineTest_math.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public void RADIANS_test()
129129
{
130130
AlgorithmEngine engine = new AlgorithmEngine();
131131
var t = engine.TryEvaluate("RADIANS(180)", 0.0);
132-
Assert.AreEqual(Math.PI, t);
132+
Assert.AreEqual(Math.PI, t,10);
133133
}
134134
[Test]
135135
public void cos_test()

csharp/ToolGood.Algorithm2.Test/AlgorithmEngine/Cylinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected override Operand ExecuteDiyFunction(string funcName, List<Operand> ope
3939
{
4040
if (operands.Count == 1)
4141
{
42-
var r = operands[0].ToNumber().NumberValue;
42+
var r = (double)operands[0].ToNumber().NumberValue;
4343
return r * r * Math.PI;
4444
}
4545
}

csharp/ToolGood.Algorithm2.Test/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ static void Main(string[] args)
1515

1616

1717

18-
double a = 0.0;
18+
decimal a = 0.0m;
1919
if (engine.Parse("1+2")) {
2020
var o = engine.Evaluate();
2121
a = o.NumberValue;

csharp/ToolGood.Algorithm2/AlgorithmEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ public double TryEvaluate(string exp, double def)
558558
LastError = obj.ErrorMsg;
559559
return def;
560560
}
561-
return obj.NumberValue;
561+
return (double)obj.NumberValue;
562562
}
563563
} catch (Exception ex) {
564564
LastError = ex.Message + "\r\n" + ex.StackTrace;

csharp/ToolGood.Algorithm2/AlgorithmEngineEx.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ public double TryEvaluateCategory(string categoryName, double def)
626626
LastError = obj.ErrorMsg;
627627
return def;
628628
}
629-
return obj.NumberValue;
629+
return (double)obj.NumberValue;
630630
} catch (Exception ex) {
631631
LastError = ex.Message + "\r\n" + ex.StackTrace;
632632
}
@@ -927,7 +927,7 @@ public double TryEvaluate(string exp, double def)
927927
LastError = obj.ErrorMsg;
928928
return def;
929929
}
930-
return obj.NumberValue;
930+
return (double)obj.NumberValue;
931931
} catch (Exception ex) {
932932
LastError = ex.Message + "\r\n" + ex.StackTrace;
933933
}

csharp/ToolGood.Algorithm2/Internals/MathVisitor.cs

Lines changed: 421 additions & 421 deletions
Large diffs are not rendered by default.

csharp/ToolGood.Algorithm2/LitJson/IJsonWrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface IJsonWrapper
1111
bool IsNull { get; }
1212

1313
void SetBoolean(bool val);
14-
void SetDouble(double val);
14+
void SetDouble(decimal val);
1515
void SetJsonType(JsonType type);
1616
void SetString(string val);
1717
void SetNull();

csharp/ToolGood.Algorithm2/LitJson/JsonData.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ sealed class JsonData : IJsonWrapper, IEnumerable
1010
#region Fields
1111
private IList<JsonData> inst_array;
1212
private bool inst_boolean;
13-
private double inst_double;
13+
private decimal inst_double;
1414
internal IDictionary<string, JsonData> inst_object;
1515
private string inst_string;
1616
private JsonType type;
@@ -72,10 +72,10 @@ void IJsonWrapper.SetBoolean(bool val)
7272
inst_boolean = val;
7373
}
7474

75-
void IJsonWrapper.SetDouble(double val)
75+
void IJsonWrapper.SetDouble(decimal val)
7676
{
7777
type = JsonType.Double;
78-
inst_double = val;
78+
inst_double = (decimal)val;
7979
}
8080

8181
void IJsonWrapper.SetString(string val)
@@ -154,7 +154,7 @@ void IJsonWrapper.SetJsonType(JsonType type)
154154
break;
155155

156156
case JsonType.Double:
157-
inst_double = default(Double);
157+
inst_double = default(decimal);
158158
break;
159159

160160
case JsonType.Boolean:
@@ -172,7 +172,7 @@ public IEnumerator GetEnumerator()
172172

173173

174174
public bool BooleanValue { get { return inst_boolean; } }
175-
public double NumberValue { get { return inst_double; } }
175+
public decimal NumberValue { get { return inst_double; } }
176176
public string StringValue { get { return inst_string; } }
177177
}
178178
}

csharp/ToolGood.Algorithm2/LitJson/JsonMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ private static IJsonWrapper ReadValue(JsonReader reader)
1919
}
2020

2121
if (reader.Token == JsonToken.Double) {
22-
instance.SetDouble((double)reader.Value);
22+
instance.SetDouble((decimal)reader.Value);
2323
return instance;
2424
}
2525

0 commit comments

Comments
 (0)