{"ScriptPreparationCode":"var i;\r\nvar r;\r\nvar v = 2**16;\r\n\r\nfunction test1() {\r\n for(i=0; i \u003C 1000; \u002B\u002Bi) {\r\n r = getTheMiddle(v);\r\n }\r\n}\r\n\r\nfunction test2() {\r\n for(i=0; i \u003C 1000; \u002B\u002Bi) {\r\n r = Q_rsqrt(v) * v;\r\n }\r\n}\r\nfunction getTheMiddle(number){\r\n var start = 0;\r\n var end = number;\r\n var theMiddle = (start\u002Bend)/2;\r\n while (Math.abs(theMiddle*theMiddle - number) \u003E 0.00001)\r\n {\r\n if (theMiddle*theMiddle \u003E number)\r\n {\r\n end = theMiddle;\r\n }\r\n else\r\n {\r\n start = theMiddle;\r\n }\r\n \r\n theMiddle = (start\u002Bend)/2;\r\n return theMiddle;\r\n }\r\n}\r\n//Based on the fast inverse square root function\r\n// https://en.wikipedia.org/wiki/Fast_inverse_square_root\r\n// Some original comments preserved for humor value\r\n// Designed to try to mimic the original as closely as possible\r\nfunction Q_rsqrt(number)\r\n{ \r\n var i;\r\n var x2, y;\r\n const threehalfs = 1.5;\r\n \r\n x2 = number * 0.5;\r\n y = number;\r\n //evil floating bit level hacking\r\n var buf = new ArrayBuffer(4);\r\n (new Float32Array(buf))[0] = number;\r\n i = (new Uint32Array(buf))[0];\r\n i = (0x5f3759df - (i \u003E\u003E 1)); //What the fuck?\r\n (new Uint32Array(buf))[0] = i;\r\n y = (new Float32Array(buf))[0];\r\n y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration\r\n// y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed\r\n\r\n return y;\r\n}","TestCases":[{"Name":"the middle","Code":"test1();","IsDeferred":false},{"Name":"fisqrt","Code":"test2();","IsDeferred":false}]}