/// <summary> /// Tries to unify the constraints of a method call /// </summary> /// <param name="methodAnalyzed">The method that is being analyzed when the operation is performed.</param> /// <param name="actualImplicitObject">Only suitable in an assignment constraint. It represents the actual object used to pass the message.</param> /// <param name="showInvocationMessage">To show the invocation line and column in case an error exists</param> /// <param name="location">The original location where the constraint has been generated</param> public override TypeExpression Check(MethodType methodAnalyzed, TypeExpression actualImplicitObject, bool showInvocationMessage, SortOfUnification activeSortOfUnification, Location location) { TypeExpression result; if (this.IsBinary) { result = (TypeExpression)this.FirstOperand.AcceptOperation(ArithmeticalOperation.Create(this.SecondOperand, this.BinaryOperator, methodAnalyzed, true, this.Location), null); } else // * Unary { result = (TypeExpression)this.FirstOperand.AcceptOperation(ArithmeticalOperation.Create(this.UnaryOperator, methodAnalyzed, true, this.Location), null); } if (result == null && showInvocationMessage) { ErrorManager.Instance.NotifyError(new ConstraintError(location)); return(null); } // * If no error exists, we unify the return type variable with the actual result this.ReturnType.Unify(result, SortOfUnification.Equivalent, new List <Pair <TypeExpression, TypeExpression> >()); this.ReturnType.ValidTypeExpression = this.ValidTypeExpression = false; return(this.ReturnType); }
private static Polynomial Calculate(Polynomial a, Polynomial b, ArithmeticalOperation methodArithmeticalOperation) { var multipliers = a._multipliers.Length > b._multipliers.Length ? new double[a._multipliers.Length] : new double[b._multipliers.Length]; int i = 0; double m = 0.0; do { if (a._multipliers.Length - 1 < i) { AppendMulsOver(ref multipliers, i, b._multipliers); return new Polynomial(multipliers); } else if (b._multipliers.Length - 1 < i) { AppendMulsOver(ref multipliers, i, a._multipliers); return new Polynomial(multipliers); } m = methodArithmeticalOperation(a._multipliers[i], b._multipliers[i]); multipliers[i] = m; ++i; } while (i <= a._multipliers.Length && i <= b._multipliers.Length); return new Polynomial(multipliers); }