/// <summary> /// Does the math operation. /// </summary> private void do_math_operation() { /// <sumamry> Variable lastOperator stores last operation which will be performed </summary> switch (lastOperator) { case "+": operand1 = Math.Add(operand1, dispString_to_numb(display.Text)); break; case "-": operand1 = Math.Add(operand1, -(dispString_to_numb(display.Text))); break; case "*": operand1 = Math.Mul(operand1, dispString_to_numb(display.Text)); break; case "/": operand1 = Math.Div(operand1, dispString_to_numb(display.Text)); break; case "power": operand1 = Math.Pow(operand1, dispString_to_numb(display.Text)); break; case "root": operand1 = Math.Root(operand1, dispString_to_numb(display.Text)); break; case "log": operand1 = Math.Log(dispString_to_numb(display.Text), operand1); break; default: break; } }
public void LogTest() { Assert.AreEqual(0, math.Log(10, 1)); Assert.AreEqual(10, math.Log(2, 1024)); Assert.AreEqual(1, math.Log(0.5, 0.5), Exactness); Assert.AreEqual(1.283513, math.Log(100, 369), Exactness); Assert.AreEqual(-4.923343, math.Log(0.8, 3), Exactness); Assert.AreEqual(5.395507, math.Log(0.8, 0.3), Exactness); Assert.AreEqual(-0.748070, math.Log(5, 0.3), Exactness); /// <summary> NaN result</summary> string noFailMessage = "No exception message when result was NaN."; try { math.Log(0, 1); Assert.Fail(noFailMessage); } catch (Exception) { } try { math.Log(1, 10); Assert.Fail(noFailMessage); } catch (Exception) { } try { math.Log(-3, 10); Assert.Fail(noFailMessage); } catch (Exception) { } try { math.Log(10, -3); Assert.Fail(noFailMessage); } catch (Exception) { } }