private BitArray Subtraction() //11 { var result = FirstOperand.ToInt() - SecondOperand.ToInt(); ThirdOperand = BitArrayExtension.GetBitArray(result, OperandLenght); return(ThirdOperand); }
private void ResetOperandsToDefault() { FirstOperand.Clear(); FirstOperand = new StringBuilder("0"); SecondOperand.Clear(); SecondOperand = new StringBuilder("0"); }
private BitArray Multiplication() //12 { var result = FirstOperand.ToInt() * SecondOperand.ToInt(); ThirdOperand = BitArrayExtension.GetBitArray(result, OperandLenght); return(ThirdOperand); }
/// <summary> /// /// </summary> /// <returns></returns> public override string GetParameterValue() { StringBuilder sb = new StringBuilder(); sb.Append(FirstOperand.GetParameterValue()); switch (Operation) { case MathOperation.Division: sb.Append("/"); break; case MathOperation.Minus: sb.Append("-"); break; case MathOperation.Multiplication: sb.Append("*"); break; case MathOperation.Plus: sb.Append("+"); break; } sb.Append(SecondOperand.GetParameterValue()); return(sb.ToString()); }
private BitArray StrongDivision() //13 { var result = FirstOperand.ToInt() / SecondOperand.ToInt(); ThirdOperand = BitArrayExtension.GetBitArray(result, OperandLenght); return(ThirdOperand); }
private BitArray Modulo() //14 { var result = FirstOperand.ToInt() % SecondOperand.ToInt(); ThirdOperand = BitArrayExtension.GetBitArray(result, OperandLenght); return(ThirdOperand); }
private BitArray Addition() //10 { var result = FirstOperand.ToInt() + SecondOperand.ToInt(); ThirdOperand = BitArrayExtension.GetBitArray(result, OperandLenght); return(ThirdOperand); }
/// <inheritdoc/> public override ushort GetValue(Environment environment) { Console.WriteLine($"Evaluating {this}"); var leftSide = FirstOperand.GetValue(environment); var rightSide = SecondOperand.GetValue(environment); return((ushort)(leftSide & rightSide)); }
public void Execute() { double firstOperand = 0; double secondOperand = 0; try { firstOperand = double.Parse(PrepareToParse(FirstOperand.ToString())); secondOperand = double.Parse(PrepareToParse(SecondOperand.ToString())); } catch (System.FormatException e) { Console.WriteLine(e.Message); } double result = 0; switch (actionOperator) { case "+": { result = operacja.Addition(firstOperand, secondOperand); break; } case "-": { result = operacja.Substraction(firstOperand, secondOperand); break; } case "/": { result = operacja.Division(firstOperand, secondOperand); break; } case "x": { result = operacja.Multiplication(firstOperand, secondOperand); break; } case "%": { result = operacja.Percentage(firstOperand, secondOperand); break; } default: { Result = "0"; break; } } Result = result.ToString().Replace(',', '.'); ResetOperandsToDefault(); ResetIsOperandChosen(); }
/// <summary> /// Clones this instance. /// </summary> /// <returns>A deep copy of this instance.</returns> public override ActionParameterViewModelBase Clone() { return(new MathExpressionParameterViewModel(new MathExpressionParameter(), _parameterDescriptor, AllParameterDescriptions) { FirstOperand = FirstOperand.Clone(), SecondOperand = SecondOperand.Clone(), Operation = Operation }); }
protected override bool MeetsCriterion(VisualPayload payload) { var comparisonType = ComparisonTypeField.GetFirstValue(payload.Data); var firstOperand = FirstOperand.GetFirstValue(payload.Data); var secondOperand = SecondOperand.GetFirstValue(payload.Data); return(ComparisonPredicates[comparisonType](firstOperand, secondOperand)); }
public override int GetHashCode() { var hashCode = -655746530; hashCode = hashCode * -1521134295 + FirstOperand.GetHashCode(); hashCode = hashCode * -1521134295 + Operator.GetHashCode(); hashCode = hashCode * -1521134295 + SecondOperand.GetHashCode(); return(hashCode); }
public override string GetStepParameters() { var parameters = new List <string>(); parameters.Add(Operator != null ? Operator.ToStepValue() : "$"); parameters.Add(FirstOperand != null ? FirstOperand.ToStepValue() : "$"); parameters.Add(SecondOperand != null ? SecondOperand.ToStepValue() : "$"); return(string.Join(", ", parameters.ToArray())); }
public override int GetHashCode() { unchecked { var hashCode = FirstOperand.GetHashCode(); hashCode = (hashCode * 397) ^ SecondOperand.GetHashCode(); hashCode = (hashCode * 397) ^ Operation.GetHashCode(); return(hashCode); } }
/// <summary> /// In case of a Boolean operation failure, provide a recommended direction to shift the geometry in for a second attempt. /// </summary> /// <param name="lcs">The local transform for this entity.</param> /// <returns>An XYZ representing a unit direction vector, or null if no direction is suggested.</returns> /// <remarks>If the 2nd attempt fails, a third attempt will be done with a shift in the opposite direction.</remarks> public XYZ GetSuggestedShiftDirection(Transform lcs) { XYZ suggestedXYZ = (SecondOperand == null) ? null : SecondOperand.GetSuggestedShiftDirection(lcs); if (suggestedXYZ == null) { suggestedXYZ = (FirstOperand == null) ? null : FirstOperand.GetSuggestedShiftDirection(lcs); } return(suggestedXYZ); }
public string DisplayOperand() { if (isOperandChosen == false) { return(FirstOperand.ToString()); } else { return(SecondOperand.ToString()); } }
public override int GetHashCode() { unchecked { var hashCode = (Label != null ? Label.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (LeftPartIdentifier != null ? LeftPartIdentifier.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (FirstOperand != null ? FirstOperand.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (SecondOperand != null ? SecondOperand.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Operation != null ? Operation.GetHashCode() : 0); return(hashCode); } }
public void DelButton() { if (String.IsNullOrEmpty(Operator)) { FirstOperand.Del(); NotifyOfPropertyChange(() => Result); } else { SecondOperand.Del(); NotifyOfPropertyChange(() => Result); } }
protected override MutableObject Mutate(MutableObject mutable) { foreach (var entry in Scope.GetEntries(mutable)) { var comparison = Comparison.GetValue(entry); var firstOperand = FirstOperand.GetValue(entry); var secondOperand = SecondOperand.GetValue(entry); ResultTarget.SetValue(IfCompareMutator.ComparisonPredicates[comparison](firstOperand, secondOperand), entry); } return(mutable); }
private BitArray GetNumInSecOperandBase() //17 { var num = FirstOperand.ToInt(); var bs = SecondOperand.ToInt(); if (bs > 36 || bs < 0) { ShowMessage("Incorrect Base"); return(BitArrayExtension.GetBitArray(0, 9)); } ShowMessage(ConvertToBase(num, bs)); return(BitArrayExtension.GetBitArray(num, 1)); }
private BitArray FindMaxDivider() //19 { var num = FirstOperand.ToInt(); int divider = 0; for (int i = 0; i < 10; i++) { if (num % (int)Math.Pow(2, i) == 0) { divider = i; } } ThirdOperand = BitArrayExtension.GetBitArray(divider, OperandLenght); return(ThirdOperand); }
public string ToFunctionName() { string ret = Operation; if (FirstOperand != string.Empty) { ret += "_" + FirstOperand.Replace("(", "MEM_").Replace(")", "").Replace("+", "_"); if (SecondOperand != string.Empty) { ret += "_" + SecondOperand.Replace("(", "MEM_").Replace(")", "").Replace("+", "_"); } } return(ret); }
public void PercentButton() { if (String.IsNullOrEmpty(Operator)) { decimal result = Convert.ToDecimal(FirstOperand.FullPart); result = (result == 0 ? (decimal)(1f / 100f) : (decimal)(result / 100)); FirstOperand.Equal(result); } else { decimal result = Convert.ToDecimal(SecondOperand.FullPart); result = (result == 0 ? (decimal)(1f / 100f) : (decimal)(result / 100)); SecondOperand.Equal(result); } NotifyOfPropertyChange(() => Result); }
private BitArray GetOperandsList() //0 { var bs = FirstOperand.ToInt(); if (bs > 36 || bs < 2) { ShowMessage("Incorrect Base"); return(null); } string result = ConvertToBase(ThirdOperand.ToInt(), bs) + " " + ConvertToBase(SecondOperand.ToInt(), bs) + " " + ConvertToBase(FirstOperand.ToInt(), bs) + " " + ConvertToBase(Operation.ToInt(), bs); ShowMessage(result); return(null); }
public void EqualButton() { decimal result; Expression = Result; try { switch (Operator) { case "+": result = Convert.ToDecimal(FirstOperand.FullPart) + Convert.ToDecimal(SecondOperand.FullPart); SecondOperand = new Operand(); FirstOperand.Equal(result); Operator = ""; break; case "-": result = Convert.ToDecimal(FirstOperand.FullPart) - Convert.ToDecimal(SecondOperand.FullPart); SecondOperand = new Operand(); FirstOperand.Equal(result); Operator = ""; break; case "*": result = Convert.ToDecimal(FirstOperand.FullPart) * Convert.ToDecimal(SecondOperand.FullPart); SecondOperand = new Operand(); FirstOperand.Equal(result); Operator = ""; break; case "/": result = Convert.ToDecimal(FirstOperand.FullPart) / Convert.ToDecimal(SecondOperand.FullPart); SecondOperand = new Operand(); FirstOperand.Equal(result); Operator = ""; break; default: return; } NotifyOfPropertyChange(() => Result); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public override int GetHashCode() { int hash = 1; if (FirstOperand != 0) { hash ^= FirstOperand.GetHashCode(); } if (SecondOperand != 0) { hash ^= SecondOperand.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
/// <summary> /// Gets the parameter value. /// </summary> /// <param name="rootModel">The root model.</param> /// <param name="context">The context.</param> /// <returns> /// Parameter value. /// </returns> public override string GetParameterValue(RootModel rootModel, ActionExecutionContext context) { Assert.ArgumentNotNull(rootModel, "rootModel"); Assert.ArgumentNotNull(context, "context"); var leftVal = FirstOperand.GetParameterValue(rootModel, context); var rightVal = SecondOperand.GetParameterValue(rootModel, context); double leftValueNumeric; double rightValueNumertic; bool isLeftValueNumeric = double.TryParse(leftVal, NumberStyles.Any, CultureInfo.InvariantCulture, out leftValueNumeric); bool isRightValueNumeric = double.TryParse(rightVal, NumberStyles.Any, CultureInfo.InvariantCulture, out rightValueNumertic); if (isRightValueNumeric && isLeftValueNumeric) { switch (Operation) { case MathOperation.Plus: return((leftValueNumeric + rightValueNumertic).ToString(CultureInfo.InvariantCulture)); case MathOperation.Minus: return((leftValueNumeric - rightValueNumertic).ToString(CultureInfo.InvariantCulture)); case MathOperation.Multiplication: return((leftValueNumeric * rightValueNumertic).ToString(CultureInfo.InvariantCulture)); case MathOperation.Division: return(rightValueNumertic == 0 ? string.Empty : (leftValueNumeric / rightValueNumertic).ToString(CultureInfo.InvariantCulture)); } } else { if (Operation == MathOperation.Plus) { return(leftVal + rightVal); } } return(string.Empty); }
/// <summary> /// Update the display text /// </summary> /// <param name="showResult">Display the result or the current calculation</param> private void UpdateDisplay(bool showResult = false) { if (!showResult) { if (Operation != CalculatorOperation.Unknown) { display.text = string.Format("{0} {1} {2}", FirstOperand, OperationToString(), SecondOperand != 0 ? SecondOperand.ToString() : "").Trim(); } else { display.text = FirstOperand.ToString(); } } else { display.text = Result.ToString(); } }
public void CalculateResult() { try { switch (Operation) { case ("+"): Result = (FirstOperand.ToDouble() + SecondOperand.ToDouble()).ToDisplayString(); break; case ("-"): Result = (FirstOperand.ToDouble() - SecondOperand.ToDouble()).ToDisplayString(); break; case ("*"): Result = (FirstOperand.ToDouble() * SecondOperand.ToDouble()).ToDisplayString(); break; case ("/"): Result = (FirstOperand.ToDouble() / SecondOperand.ToDouble()).ToDisplayString(); break; case ("%"): Result = (FirstOperand.ToDouble() * SecondOperand.ToDouble() / 100D).ToDisplayString(); break; case ("√"): Result = Math.Sqrt(SecondOperand.ToDouble()).ToDisplayString(); break; case ("1/x"): Result = (1 / (SecondOperand.ToDouble())).ToDisplayString(); break; } } catch (Exception) { Result = "Error"; } }
public void ModifyOperand(string commandString) { if (operationStage == OperationStage.DisplayResult) { MoveResultToFirstOperand(); } switch (commandString) { case ".": { GetCurrentOperandObject().SetHasAPoint(true); break; } case "%": { GetCurrentOperandObject().DivideBy100(); break; } case "+/-": { GetCurrentOperandObject().Invert(); break; } case "C": { FirstOperand.Reset(); SecondOperand.Reset(); ResultOperand.Reset(); operationStage = OperationStage.EnterFirstOperand; break; } } }