Calculator
Calculator copied to clipboard
Wrong calc on power?
Hi
Looks like the calculator has issues with power and brackets. 50 - (2 ^ 5) - 5 13 is correct 50 - 2 ^ 5 - 5 254803963 is wrong should be also 13
Regards
I'm not sure this is wrong, if i paste 50 - 2 ^ 5 - 5 into c# interactive, i get 48. I paste it into google, it converts it to 50 - (2 ^ 5) - 5. I'll do some more research.
Hi
Accoring to https://en.wikipedia.org/wiki/Order_of_operations the following order has to be applied: exponents and roots multiplication and division addition and subtraction
It means that 50 - 2 ^ 5 - 5 has to be executed as 50 - (2 ^ 5) - 5. Simular as 50 - 2 * 5 - 5 is a the same as 50 - (2 * 5) - 5
Regards
@pwelter34 This is because in C# 50 - 2 ^5 - 5 means (50 - 2) XOR (5 - 5), which is 48. Also, this should be irrelevant, as a calculator should follow rules of mathematics, not programming languages anyway. Please fix this!
private static int Precedence(string c)
{
if (c.Length == 1 && (c[0] == '^'))
return 3;
if (c.Length == 1 && (c[0] == '*' || c[0] == '/' || c[0] == '%'))
return 2;
return 1;
}
from https://lifeinhex.com/deobfuscating-autoit-scripts-part-2/