加入自动类型转换
This commit is contained in:
@@ -1,12 +1,62 @@
|
||||
using Flee.PublicTypes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Convention.RScript.Parser
|
||||
namespace Convention.RScript
|
||||
{
|
||||
public static class ExpressionMath
|
||||
{
|
||||
public static int Sign(double value, double accuracy = ExpressionExtension.DefaultDoubleAccuracy)
|
||||
{
|
||||
if (value.IsCloseToZero(accuracy))
|
||||
return 0;
|
||||
return value > 0 ? 1 : -1;
|
||||
}
|
||||
|
||||
public static int Compare(double value1, double value2, double accuracy = ExpressionExtension.DefaultDoubleAccuracy)
|
||||
{
|
||||
if (value1.IsClose(value2, accuracy))
|
||||
return 0;
|
||||
return value1 > value2 ? 1 : -1;
|
||||
}
|
||||
|
||||
public static bool IsBetween(double value, double minValue, double maxValue, double accuracy = ExpressionExtension.DefaultDoubleAccuracy)
|
||||
{
|
||||
return Compare(value, minValue, accuracy) >= 0 && Compare(value, maxValue, accuracy) <= 0;
|
||||
}
|
||||
|
||||
public static bool IsBetweenExclusive(double value, double minValue, double maxValue, double accuracy = ExpressionExtension.DefaultDoubleAccuracy)
|
||||
{
|
||||
return Compare(value, minValue, accuracy) > 0 && Compare(value, maxValue, accuracy) < 0;
|
||||
}
|
||||
|
||||
public static int ToInt(double value)
|
||||
{
|
||||
return (int)value;
|
||||
}
|
||||
|
||||
public static int ToInt(float value)
|
||||
{
|
||||
return (int)value;
|
||||
}
|
||||
public static int ToInt(int value)
|
||||
{
|
||||
return (int)value;
|
||||
}
|
||||
|
||||
public static double ToDouble(float value)
|
||||
{
|
||||
return (double)value;
|
||||
}
|
||||
|
||||
public static double ToDouble(int value)
|
||||
{
|
||||
return (double)value;
|
||||
}
|
||||
public static double ToDouble(double value)
|
||||
{
|
||||
return (double)value;
|
||||
}
|
||||
}
|
||||
public static class ExpressionExtension
|
||||
{
|
||||
public const double DefaultDoubleAccuracy = 1e-7;
|
||||
@@ -32,7 +82,10 @@ namespace Convention.RScript.Parser
|
||||
return !(double.IsInfinity(value) || double.IsNaN(value) || value > maximumAbsoluteError || value < -maximumAbsoluteError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Convention.RScript.Parser
|
||||
{
|
||||
public class ExpressionParser
|
||||
{
|
||||
public readonly ExpressionContext context;
|
||||
|
Reference in New Issue
Block a user