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(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 ComOperation2() { switch (this.op2) { case CalculatorOperation2.Sqrt: if (input < 0) { InputError?.Invoke(this, "Negative number under the root"); return; } input = Math.Sqrt(input ?? 0) * 1.0; didUpdateValue?.Invoke(this, input.Value, 0); break; case CalculatorOperation2.Sqr: input = Math.Pow((input ?? 0), 2); didUpdateValue?.Invoke(this, input.Value, 0); break; case CalculatorOperation2.Gip: input = 1.0 / (input ?? 0); didUpdateValue?.Invoke(this, input.Value, 0); break; case CalculatorOperation2.Proc: input = ((result ?? 0) * input) / 100; didUpdateValue?.Invoke(this, input.Value, 0); break; } }
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 (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 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(int digit) { if (fractionDigits.HasValue == false) { if (input.HasValue && Math.Log10(input.Value) > 10) { InputError?.Invoke(this, "Value is too long for this calculator"); return; } input = (input ?? 0) * 10 + digit; } else { fractionDigits++; input = (input ?? 0) + digit * Math.Pow(10, -fractionDigits.Value); } didUpdateValue?.Invoke(this, input.Value, fractionDigits ?? 0); }
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 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 ComputeUnar() { switch (currentOp) { case Operation.Sqrt: if (left < 0) { InputError?.Invoke(this, "Error"); return; } right = Math.Sqrt((double)left); break; case Operation.Log: if (left < 0) { InputError?.Invoke(this, "Error"); return; } 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 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); }
public void AddDigit(int digit) { if (!hasPoint) { if (input.HasValue && Math.Log10(input.Value) > 9) { InputError?.Invoke(this, "Value too long"); return; } input = (input ?? 0) * 10 + digit; } else { if (fractionDigits > 8) { InputError?.Invoke(this, "Value too long"); return; } fractionDigits++; input = (input ?? 0) + digit * Math.Pow(10, -fractionDigits); } DidUpdateValue?.Invoke(this, input.Value, fractionDigits); }