{"ScriptPreparationCode":"const ONEQTR_PI = Math.PI / 4;\r\nconst THRQTR_PI = (3 * Math.PI) / 4;\r\n\r\nconst HALF_PI = Math.PI / 2;\r\n\r\n// https://gist.github.com/volkansalma/2972237#file-atan2_approximation-c-L29\r\nconst fastAtan2 = (y, x) =\u003E {\r\n\tconst abs_y = Math.abs(y) \u002B 1e-10; // kludge to prevent 0/0 condition\r\n\tlet angle, r;\r\n\tif (x \u003C 0) {\r\n\t\tr = (x \u002B abs_y) / (abs_y - x);\r\n\t\tangle = THRQTR_PI;\r\n\t} else {\r\n\t\tr = (x - abs_y) / (x \u002B abs_y);\r\n\t\tangle = ONEQTR_PI;\r\n\t}\r\n\tangle \u002B= (0.1963 * r * r - 0.9817) * r;\r\n\treturn y \u003C 0 ? -angle : angle;\r\n};\r\n\r\n// https://mazzo.li/posts/vectorized-atan2.html\r\nconst accurateFastAtan2 = (y, x) =\u003E {\r\n\tconst swap = Math.abs(x) \u003C Math.abs(y);\r\n\tconst denominator = (swap ? y : x) === 0 ? 0.00000001 : swap ? y : x;\r\n\tconst atan_input = (swap ? x : y) / denominator;\r\n\r\n\tconst a1 = 0.99997726;\r\n\tconst a3 = -0.33262347;\r\n\tconst a5 = 0.19354346;\r\n\tconst a7 = -0.11643287;\r\n\tconst a9 = 0.05265332;\r\n\tconst a11 = -0.0117212;\r\n\r\n\tconst z_sq = atan_input * atan_input;\r\n\tlet res = atan_input * (a1 \u002B z_sq * (a3 \u002B z_sq * (a5 \u002B z_sq * (a7 \u002B z_sq * (a9 \u002B z_sq * a11)))));\r\n\r\n\tif (swap) res = Math.sign(atan_input) * HALF_PI - res;\r\n\tif (x \u003C 0.0) res = Math.sign(y) * MATH.PI \u002B res;\r\n\r\n\treturn res;\r\n};","TestCases":[{"Name":"Math.atan2","Code":"eval(\u0027\u0027);\r\nvar k = [1, .23, 0.12, 929, 8172, 9.2, 21.2].map(e =\u003E Math.atan2(e, .5));","IsDeferred":false},{"Name":"fast approx. atan2","Code":"eval(\u0027\u0027);\r\nvar k = [1, .23, 0.12, 929, 8172, 9.2, 21.2].map(e =\u003E fastAtan2(e, .5));","IsDeferred":false},{"Name":"accurate approx atan2","Code":"eval(\u0027\u0027);\r\nvar k = [1, .23, 0.12, 929, 8172, 9.2, 21.2].map(e =\u003E accurateFastAtan2(e, .5));","IsDeferred":false}]}