No one here has presented any examples of exactly how an equation can return different results, for example, comparing 37/6 with 37%6 , and before some of you are upset thinking you did it, stop for a moment and think about it for a minute, according to Dirk Folmar, here int x % int y analyzes as (x - (x / y) * y) , which seems pretty simple at first glance, but not all Math is executed in the same order.
Since each equation does not have the right brackets, some schools will explain that the equation should be analyzed as ((x - (x / y)) * y) , while other schools will teach (x - ((x / y) * y)) .
Now I was experimenting with my example ( 37/6 and 37%6 ) and figured out what choice was intended (it (x - ((x / y) * y)) ), and I even showed a beautifully constructed if loop (although I forgot each End of the linear semicolon) to simulate the separation equation in the most fundamental scale, since this was actually my point, the equation is similar, but fundamentally different. Here's what I can remember from my remote Mail (it took me around the Hour to print from my phone, indentation with double spacing)
using System; class Test { static void Main() { float exact0 = (37 / 6); //6.1666eβ float exact1 = (37 % 6); //1 float exact2 = (37 - (37 / 6) * 6); //0 float exact3 = ((37 - (37 / 6)) * 6); //0 float exact4 = (37 - ((37 / 6) * 6)); //185 int a = 37; int b = 6; int c = 0; int d = a; int e = b; string Answer0 = ""; string Answer1 = ""; string Answer2 = ""; string Answer0Alt = ""; string Answer1Alt = ""; string Answer2Alt = ""; Console.WriteLine("37/6: " + exact0); Console.WriteLine("37%6: " + exact1); Console.WriteLine("(37 - (37 / 6) * 6): " + exact2); Console.WriteLine("((37 - (37 / 6)) * 6): " + exact3); Console.WriteLine("(37 - ((37 / 6) * 6)): " + exact4); Console.WriteLine("a: " + a + ", b: " + b + ", c: " + c + ", d: " + d + ", e: " + e); Console.WriteLine("Answer0: " + Answer0); Console.WriteLine("Answer0Alt: " + Answer0Alt); Console.WriteLine("Answer1: " + Answer1); Console.WriteLine("Answer0Alt: " + Answer1Alt); Console.WriteLine("Answer2: " + Answer2); Console.WriteLine("Answer2Alt: " + Answer2Alt); Console.WriteLine("Init Complete, starting Math..."); Loop { if (a !< b) { a - b; c +1;} if else (a = b) { a - b; c +1;} else { String Answer0 = c + "." + a; //6.1 //this is = to 37/6 in the fact that it equals 6.1 ((6*6=36)+1=37) or 6 remainder 1, //which according to my Calculator App is technically correct once you Round Down the .666eβ //which has been stated as the default behavior of the C
It also PURE demonstrated how the result may differ for the same equation.
Blue64
source share