public UnaryExpr(UnaryOperationType type, Element value, TextRange range) : base(range) { Contract.Requires <ArgumentNullException>(value != null); this.ExprType = type; this.Value = value; }
public static Operator Parse(string oper, int num) { int indexOfEquals = oper.LastIndexOf("="); string assigned = oper.Substring(0, indexOfEquals); if (IsUnacceptableIdentifier(assigned)) { throw new FormatException("Ошибка в задании цели присваивания (неверный идентификатор)"); } int indexOfSign = oper.Length - 1; UnaryOperationType operationType = GetUnaryOperationType(oper.ElementAt(indexOfSign)); if (operationType == UnaryOperationType.NotSpecified) { throw new FormatException("Несуществующая операция"); } string operand = oper.Substring(indexOfEquals + 1, (indexOfSign - indexOfEquals - 1)); if (IsUnacceptableIdentifier(assigned)) { throw new FormatException("Ошибка в задании операнда (неверный идентификатор)"); } UnaryOperator operation = new UnaryOperator(assigned, operand, operationType, num); return(operation); }
private static void RandomTestTrigonometryOperation(UnaryOperationType op) { Func <float, float> func = op switch { UnaryOperationType.Sine => MathF.Sin, UnaryOperationType.Cosine => MathF.Cos, UnaryOperationType.Tangent => MathF.Tan, _ => throw new ArgumentException(), }; PCG rand = new PCG(0, 0); // small values for (int i = 0; i < RandomTestCount; ++i) { float x = rand.FloatInclusive(-1.0f, 1.0f); TestTrigonometryOperationApproximate(x, func(x), op); } // medium values for (int i = 0; i < RandomTestCount; ++i) { float x = rand.FloatInclusive(-100.0f, 100.0f); TestTrigonometryOperationApproximate(x, func(x), op); } }
public UnaryOperationSyntax(UnaryOperationType type, T operand) { Type = type; Operand = operand == null ? throw new ArgumentNullException(nameof(operand)) : operand; }
private static void TestUnaryOperationFloatExact(float x, float expected, UnaryOperationType op) { UnaryOperation func = unaryOperations[(int)op]; sfloat result = func((sfloat)x); bool isOk = result.Equals((sfloat)expected); Debug.Assert(isOk); }
/// <summary> /// Creates a new UnOpItem with the given state. /// </summary> /// <param name="target">The target expression.</param> /// <param name="type">The type of operation.</param> /// <exception cref="System.ArgumentNullException">If target is null.</exception> public UnOpItem(IParseExp target, UnaryOperationType type) { if (target == null) throw new ArgumentNullException("target"); this.target = target; this.OperationType = type; }
public UnaryOperator(string assigned, string operand, UnaryOperationType operationType, int lineNumber) : this() { Assigned = assigned; Operand = operand; OperationType = operationType; base.LineNumber = lineNumber; }
private SyntaxToken EvalUnary(ConstantSyntaxToken value, UnaryOperationType type) { switch (type) { case UnaryOperationType.Factorial: return SyntaxToken.Constant(MathEx.Factorial(value.Value)); default: throw new NotSupportedException(); } }
/// <summary> /// Creates a new UnOpItem with the given state. /// </summary> /// <param name="target">The target expression.</param> /// <param name="type">The type of operation.</param> /// <exception cref="System.ArgumentNullException">If target is null.</exception> public UnOpItem(IParseExp target, UnaryOperationType type) { if (target == null) { throw new ArgumentNullException(nameof(target)); } this.target = target; this.OperationType = type; }
private DynamicMetaObjectBinder SearchBinder(UnaryOperationType op) { switch (op) { case UnaryOperationType.Not: return(Factory.NotBinder); case UnaryOperationType.Negate: return(Factory.NegateBinder); default: return(null); } }
private static void RandomTestUnaryOperation(UnaryOperationType op, float allowedErrorMultiplier = 1.0f) { Func <float, float> func = op switch { UnaryOperationType.Round => MathF.Round, UnaryOperationType.Floor => MathF.Floor, UnaryOperationType.Ceiling => MathF.Ceiling, UnaryOperationType.Sine => MathF.Sin, UnaryOperationType.Cosine => MathF.Cos, UnaryOperationType.Tangent => MathF.Tan, UnaryOperationType.SquareRoot => MathF.Sqrt, UnaryOperationType.Exponential => MathF.Exp, UnaryOperationType.LogarithmNatural => MathF.Log, UnaryOperationType.LogarithmBase2 => MathF.Log2, UnaryOperationType.ArcSine => MathF.Asin, UnaryOperationType.ArcCosine => MathF.Acos, UnaryOperationType.ArcTangent => MathF.Atan, _ => throw new ArgumentException(), }; PCG rand = new PCG(0, 0); // very small values for (int i = 0; i < RandomTestCount; ++i) { float x = rand.FloatInclusive(-1e-40f, 1e-40f); TestUnaryOperationFloatApproximate(x, func(x), op, allowedErrorMultiplier); } // small values for (int i = 0; i < RandomTestCount; ++i) { float x = rand.FloatInclusive(-1.0f, 1.0f); TestUnaryOperationFloatApproximate(x, func(x), op, allowedErrorMultiplier); } // large values for (int i = 0; i < RandomTestCount; ++i) { float x = rand.FloatInclusive(-100000.0f, 100000.0f); TestUnaryOperationFloatApproximate(x, func(x), op, allowedErrorMultiplier); } // huge values for (int i = 0; i < RandomTestCount; ++i) { float x = rand.FloatInclusive(-1000000000.0f, 1000000000.0f); TestUnaryOperationFloatApproximate(x, func(x), op, allowedErrorMultiplier); } }
public UnaryGeneralInstruction( VirtualRegister input, VirtualRegister result, UnaryOperationType type) : base( new List <VirtualRegister> { input }, new List <VirtualRegister> { result }, new List <Tuple <VirtualRegister, VirtualRegister> > { new Tuple <VirtualRegister, VirtualRegister>(input, result) }) { this.input = input; this.result = result; this.type = type; }
public UnaryOperationNode(AstNode operand, UnaryOperationType type) { Operand = operand; Type = type; }
private static void TestUnaryOperationFloatApproximate(float x, float expected, UnaryOperationType op, float allowedErrorMultiplier = 1.0f) { UnaryOperation func = unaryOperations[(int)op]; sfloat result = func((sfloat)x); if (float.IsNaN(expected) && result.IsNaN()) { // special case, NaN-s cannot be compared return; } if (float.IsInfinity(expected) && result.IsInfinity() && MathF.Sign(expected) == result.Sign()) { // both are the same infinities return; } float allowedError = MathF.Max(1e-6f * allowedErrorMultiplier * MathF.Pow(2.0f, MathF.Log2(MathF.Abs(expected) + 1.0f)), 1e-6f); float difference = MathF.Abs((float)result - expected); bool isOk = difference <= allowedError; if (!isOk && (op == UnaryOperationType.Round || op == UnaryOperationType.Floor || op == UnaryOperationType.Ceiling)) { // Because of the loss of precision that can result from representing decimal values // as floating-point numbers or performing arithmetic operations on floating-point values, // in some cases the Round method may not appear to round midpoint values to the nearest even integer. // https://docs.microsoft.com/en-us/dotnet/api/system.math.round if (MathF.Abs(x % 1.0f) - 0.5f < 0.01f) { // x is near a midpoint, it's possible that rounding happened in a different direction isOk = MathF.Abs((float)result - expected) <= 1.0f; } } Debug.Assert(isOk); }
public UnaryOperation(IExpression expression, UnaryOperationType type) { Expression = expression; Type = type; }
private static void TestTrigonometryOperationApproximate(float x, float expected, UnaryOperationType op) { UnaryOperation func = unaryOperations[(int)op]; sfloat result = func((sfloat)x); if (float.IsNaN(expected) && result.IsNaN()) { // special case, NaN-s cannot be compared return; } if (float.IsInfinity(expected) && result.IsInfinity() && MathF.Sign(expected) == result.Sign()) { // both are the same infinities return; } float allowedError = MathF.Max(0.005f * MathF.Pow(2.0f, MathF.Log2(MathF.Abs(expected) + 1.0f)), 1e-6f); float difference = MathF.Abs((float)result - expected); bool isOk = difference <= allowedError; Debug.Assert(isOk); }
public static UnarySyntaxToken Unary(SyntaxToken value, UnaryOperationType type) { return(new UnarySyntaxToken(value, type)); }
public UnaryOperation(UnaryOperationType type) { Type = type; switch (type) { case UnaryOperationType.cos: Priority = 4; break; case UnaryOperationType.sin: Priority = 4; break; case UnaryOperationType.log: Priority = 4; break; } }
private DynamicMetaObjectBinder SearchBinder(UnaryOperationType op) { switch (op) { case UnaryOperationType.Not: return Factory.NotBinder; case UnaryOperationType.Negate: return Factory.NegateBinder; default: return null; } }
internal UnarySyntaxToken(SyntaxToken value, UnaryOperationType type) { this.Value = value; this.Type = type; }
/// <summary> /// Creates a new UnOpItem with the given state. /// </summary> /// <param name="target">The target expression.</param> /// <param name="type">The type of operation.</param> public UnOpItem(IParseExp target, UnaryOperationType type) { Target = target; OperationType = type; }
internal UnaryPredicate(object expression, UnaryOperationType operationType) { Expression = Argument.NotNull(expression, "expression"); OperationType = operationType; }
public UnaryOperation(UnaryOperationType type, Variable first, Variable result) { Type = type; First = first; Result = result; }
public UnaryGeneralTemplate(UnaryOperationType operationType) : base(new UnaryOperation(null, operationType), 1) { this.operationType = operationType; }
public UnaryOperation(Node operand, UnaryOperationType type) { this.Operand = operand; this.Type = type; }
public static Boolean IsPostfixUnary(this UnaryOperationType type) { return(type >= UnaryOperationType.PostIncrement); }
public UnaryExpr(UnaryOperationType type, Element value, TextRange range) : base(range) { Contract.Requires<ArgumentNullException>(value != null); this.ExprType = type; this.Value = value; }