public void AddDigit(int digit) { if (input.HasValue && Math.Log10(input.Value) > 9) { InputError?.Invoke(this, "Value is too long for this calculator"); return; } if (count > 8) { InputError?.Invoke(this, "Value is too long for this calculator"); return; } if (!op.HasValue) { result = null; } if (point) { count = (count ?? 0); input = ((input ?? 0) * Math.Pow(10, (double)count) + (double)digit / 10) / Math.Pow(10, (double)count); DidUpdateValue?.Invoke(this, input.Value, 0); count++; } else { input = (input ?? 0) * 10 + digit; DidUpdateValue?.Invoke(this, input.Value, 0); } }
public void Compute() { if (!(left.HasValue && currentOp.HasValue)) { return; } switch (currentOp) { case Operation.Add: right = right + left; break; case Operation.Sub: right = right - left; break; case Operation.Mul: right = right * left; break; case Operation.Div: if (left == 0) { CalculationError?.Invoke(this, "Division by 0!"); return; } right = right / left; break; } DidUpdateValue?.Invoke(this, right.Value, precision); left = 0; currentOp = null; }
public void ClearAll() { input = null; result = null; op = null; DidUpdateValue?.Invoke(this, 0, 0); }
public void Compute() { switch (currentOp) { case Operation.Add: right = left + right; left = null; break; case Operation.Sub: right = right - left; left = null; break; case Operation.Mul: right = left * right; left = null; break; case Operation.Div: if (left == 0) { CalculationError?.Invoke(this, "Division by 0!"); return; } right = right / left; left = null; break; } DidUpdateValue?.Invoke(this, right.Value, precision); }
public void AddDigit(int digit) { if (left.HasValue && Math.Log10(left.Value) > 10 || precision > 13) { InputError?.Invoke(this, "Input overflow"); return; } if (precision > 10) { InputError?.Invoke(this, "Input overflow"); return; } if (!decimalPoint) { if (left >= 0 || left == null) { left = (left ?? 0) * 10 + digit; } else { left = (left ?? 0) * 10 - digit; } } else { precision += 1; left = left + (Math.Pow(0.1, precision) * digit); } DidUpdateValue?.Invoke(this, left.Value, precision); }
public void AddDigit(int digit) { Debug.WriteLine(digit); if (hasPoint == false) { if (input.HasValue && Math.Log10(input.Value) > 9) { InputError?.Invoke(this, "Value is too long for this calculator!"); return; } input = (input ?? 0) * 10 + digit; } else { if (fractionDigits > 8) { InputError?.Invoke(this, "Value is too long for this calculator!"); return; } fractionDigits += 1; input = (input ?? 0) + digit * Math.Pow(10, -fractionDigits); } DidUpdateValue?.Invoke(this, input.Value, fractionDigits); }
public void AddDigit(double digit) { if (left.HasValue && Math.Log10(left.Value) > 10) { InputError?.Invoke(this, "Input overflow"); return; } if (!decimalPoint) { left = (left ?? 0) * 10 + digit; } else { precision += 1; if (precision == 1) { left = left + 0.1 * digit; } else { string znach1 = left.ToString() + digit.ToString(); var znach2 = double.Parse(znach1); left = znach2; } } DidUpdateValue?.Invoke(this, left.Value, precision); }
public void ComputeUnar() { switch (currentOp) { case Operation.Sqrt: right = Math.Sqrt((double)left); break; case Operation.Log: right = Math.Log((double)left); break; case Operation.Sin: right = Math.Sin((double)left); break; case Operation.Cos: right = Math.Cos((double)left); break; case Operation.Tan: right = Math.Tan((double)left); break; } left = right; DidUpdateValue?.Invoke(this, right.Value, precision); right = null; }
public void Reset() { left = 0; right = null; currentOp = null; precision = 0; DidUpdateValue?.Invoke(this, left.Value, precision); }
public void SQRT() { if (input.HasValue && left != 0) { input = Math.Sqrt((double)input); } DidUpdateValue?.Invoke(this, input.Value, count); }
public void Reverce() { if (left.HasValue && left != 0) { left *= -1; } DidUpdateValue?.Invoke(this, left.Value, precision); }
public void SQRT() { if (left.HasValue && left != 0) { left = Math.Sqrt((double)left); } DidUpdateValue?.Invoke(this, left.Value, precision); }
public void Reset() { currentOp = null; left = 0; right = null; precision = 0; decimalPoint = false; DidUpdateValue?.Invoke(this, left.Value, 0); }
public void RemoveDigit() { if (hasPoint == false) { long i = (long)input / 10; input = i; } DidUpdateValue?.Invoke(this, input.Value, fractionDigits); }
public void Compute() { switch (currentOp) { case Operation.Add: right = left + right; left = null; break; case Operation.Sub: right -= left; left = null; break; case Operation.Mul: right = left * right; left = null; break; case Operation.Div: if (left == 0) { CalculationError?.Invoke(this, "Division by 0!"); return; } right /= left; left = null; break; case Operation.Pow: right *= right; left = null; break; case Operation.Sqrt: right = Math.Sqrt((double)right); left = null; break; case Operation.Drob: right = 1 / right; left = null; break; case Operation.Sin: right = Math.Sin((double)right); left = null; break; case Operation.Cos: right = Math.Cos((double)right); left = null; break; } DidUpdateValue?.Invoke(this, right.Value, precision); }
public void Compute() { switch (currentOp) { case Operation.Add: right = left + right; left = null; precision = 0; decimalPoint = false; break; case Operation.Sub: right = right - left; left = null; precision = 0; decimalPoint = false; break; case Operation.Mul: right = left * right; left = null; precision = 0; decimalPoint = false; break; case Operation.Div: if (left == 0) { CalculationError?.Invoke(this, "Division by 0!"); return; } right = right / left; left = null; precision = 0; decimalPoint = false; break; case Operation.Pow: right = Math.Pow((double)right, (double)left); left = null; precision = 0; decimalPoint = false; break; default: currentOp = null; precision = 0; decimalPoint = false; return; } DidUpdateValue?.Invoke(this, right.Value, precision); }
public void TransformInput(CalculatorTransformation t) { input = input ?? 0; switch (t) { case CalculatorTransformation.Negate: input = -input; break; } DidUpdateValue?.Invoke(this, input.Value, fractionDigits); }
public void Sign() { if (left != null) { left = left * (-1); DidUpdateValue?.Invoke(this, left.Value, precision); } else { right = right * (-1); DidUpdateValue?.Invoke(this, right.Value, precision); } }
public void AddOperation(Operation op) { if (left.HasValue && currentOp.HasValue) { Compute(); } if (!right.HasValue) { right = left; left = 0; precision = 0; DidUpdateValue.Invoke(this, left.Value, precision); } currentOp = op; }
public void Delete() { if (!hasPoint) { input = (int)(input ?? 0) / 10; } else { input = ((int)((input ?? 0) / Math.Pow(10, -fractionDigits)) / 10) * Math.Pow(10, -(--fractionDigits)); if (fractionDigits == 0) { hasPoint = false; } } DidUpdateValue?.Invoke(this, input.Value, fractionDigits); }
public void clearSymbol() { if (decimalPoint) { left = left - (left * Math.Pow(10, precision - 1) % 1) * Math.Pow(0.1, precision - 1); precision--; if (precision == 0) { decimalPoint = false; } } else { left = (int)(left * 0.1); } DidUpdateValue?.Invoke(this, left.Value, precision); }
public void TransformInput(CalculatorTransformation t) { input = input ?? 0; switch (t) { case CalculatorTransformation.Negate: input = -input; break; case CalculatorTransformation.Percent: input /= 100; break; case CalculatorTransformation.Sqr: input *= input; break; case CalculatorTransformation.Sqrt: if (input.HasValue && input.Value >= 0) { input = Math.Sqrt(input ?? 0); } else { ComputationError.Invoke(this, "Negative Square"); } break; case CalculatorTransformation.Inverse: if (input.HasValue && input.Value != 0) { input = 1 / input; } else { ComputationError.Invoke(this, "Division by Zero"); } break; } DidUpdateValue?.Invoke(this, input.Value, fractionDigits); }
public void AddDigit(int digit) { if (left.HasValue && Math.Log10(left.Value) > 10) { InputError?.Invoke(this, "Input overflow"); return; } if (!decimalPoint) { left = (left ?? 0) * 10 + digit; } else { precision += 1; } DidUpdateValue?.Invoke(this, left.Value, precision); }
public void AddDigit(int digit) { if (left.HasValue && Math.Log10(left.Value) > 10 || left.HasValue && Math.Log10(left.Value * Math.Pow(10, precision)) > 10) { InputError?.Invoke(this, "Too many digits"); return; } if (!decimalPoint) { left = (left ?? 0) * 10 + digit; } else { precision += 1; left = (left ?? 0) + digit / Math.Pow(10, precision); } DidUpdateValue?.Invoke(this, left.Value, precision); }
public void Earse() { if (left.HasValue) { if (precision > 0) { left *= Math.Pow(10, precision); left = (left ?? 0) / 10 - (left ?? 0) % 10 / 10; precision--; left /= Math.Pow(10, precision); DidUpdateValue?.Invoke(this, left.Value, precision); } else { left = (left ?? 0) / 10 - (left ?? 0) % 10 / 10; decimalPoint = false; DidUpdateValue?.Invoke(this, left.Value, precision); } } }
public void Compute() { switch (currentOp) { case Operation.Add: right = left + right; left = null; break; case Operation.Sub: right = right - left; left = null; break; case Operation.Mul: right = left * right; left = null; break; case Operation.Div: if (left == 0) { CalculationError?.Invoke(this, "Деление на 0!"); return; } right = right / left; left = null; break; case Operation.Pow: right = Math.Pow((double)right, (double)left); left = null; break; } left = right; DidUpdateValue?.Invoke(this, right.Value, precision); right = null; currentOp = null; }
public void AddOperation(Operation op) { if (left.HasValue && currentOp.HasValue) { Compute(); } if (!right.HasValue && !(op == Operation.Sqrt || op == Operation.Cos || op == Operation.Log || op == Operation.Tan || op == Operation.Sin)) { right = left; left = 0; precision = 0; decimalPoint = false; DidUpdateValue.Invoke(this, left.Value, precision); currentOp = op; } if (left.HasValue && op == Operation.Sqrt || op == Operation.Cos || op == Operation.Log || op == Operation.Tan || op == Operation.Sin || op == Operation.Sign || op == Operation.Interest) { currentOp = op; ComputeUnar(); currentOp = null; } }
public void Compute() { switch (op) { case CalculatorOperation.Add: result = result + (input ?? 0); DidUpdateValue?.Invoke(this, result.Value, 0); input = 0; break; case CalculatorOperation.Div: if (input != null && input.Value != 0) { result = result / (input ?? 0); DidUpdateValue?.Invoke(this, result.Value, 0); input = 0; break; } else { InputError?.Invoke(this, "Division by zero"); break; } case CalculatorOperation.Mul: result = result - (input ?? 0); DidUpdateValue?.Invoke(this, result.Value, 0); input = 0; break; case CalculatorOperation.Sub: result = result * (input ?? 0); DidUpdateValue?.Invoke(this, result.Value, 0); input = 0; break; } op = null; }
public void Compute() { switch (this.op) { case CalculatorOperation.Add: result = result + input; DidUpdateValue?.Invoke(this, result.Value, 0); ResetInput(); break; case CalculatorOperation.Div: if (input.HasValue && input.Value != 0) { result = result / input; DidUpdateValue?.Invoke(this, result.Value, 0); ResetInput(); } else { ComputationError?.Invoke(this, "Division by Zero"); } break; } }
public void AddDigit(int digit) { if (left.HasValue && Math.Log10(left.Value) > 10 || precision > 13) { InputError?.Invoke(this, "Переполнение входного сигнала"); return; } if (precision > 10) { InputError?.Invoke(this, "Переполнение входного сигнала"); return; } if (!decimalPoint) { left = (left ?? 0) * 10 + digit; } else { precision += 1; left = left + (Math.Pow(0.1, precision) * digit); } DidUpdateValue?.Invoke(this, left.Value, precision); }