https://turbowarp.org/1047224394/ helpful calculator in scratch that can perform calculations and evaluate functions to arbitrary precision. === instructions === type in an expression and it will display the result. examples: 5283729292722492+2934725284942027 sqrt(-5) b = 1+sqrt(-6) (sets a variable that you can use again) sum("n", 1, 100, "n^2") => sums up the first 100 square numbers, resulting in 338350. multiline statements. eg; x=1;y=5 sets x to 1 and y to 5 at once. type setprec(number) to set the precision of the calculator. typing prec allows you to see this value. note: if you set the precision to be higher than 1000 and attempt to do calculations with certain functions, the calculator will recalculate the values of constants stored in the project (pi, e, ln(2), phi), which may freeze the project for some time. allowed list of functions: +, -, *, /, ^,%, !, sqrt, ln, log, exp, sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh, sec, csc, cot, erf, real, imag, abs, conj, angle, floor, ceil, round, sum, prod. == function explanation == note that all functions output the principal value of their respective operation unless otherwise specified, and that the trig functions use radians, not degrees. +, -, *, /: addition, subtraction, multiplication, division, respectively. ^: exponentiation* %: modulo !: factorial, analytically extended by the gamma function.* sqrt: square root operator ln: natural logarithm* log: base-10 logarithm* exp: exponential function. calculates e^x. sin, cos, tan: sine, cosine, and tangent trigonometric functions respectively. asin, acos, atan: inverse trig functions (of sine, cosine and tangent).* sinh, cosh, tanh: hyperbolic trig functions. asinh, acosh, atanh: inverse hyperbolic trig functions.* sec, csc, cot: secant, cosecant, cotangent respectively. real: the real part of a complex number input. eg: real(2+3i) = 2. imag: the imaginary part of a complex number input. eg: imag(2+3i) = 3. erf: computes the error function, which is related to the gaussian integral. abs: absolute value (or modulus) of a real or complex number. conj: complex conjugation. conj(2+3i) = 2-3i. angle: the "phase" or argument of a complex number.* floor, ceil, round: floor, ceiling, and round functions respectively. sum, prod: summation and product evaluation, respectively. the syntax for these are sum("variable", start, end, "expression"). you MUST use either quotation marks or curly braces {} for the variable and expression parameters. =: an operator to set a variable to a specific value. example usage: b = 5+8 this puts the value 13 into the b variable and can be used later at any time. note that you cannot override the values of pi, e, phi or i. ans is always set to the result of the last calculation. * if you try to use any of these marked functions at a higher precision, the calculator will recalculate the values of all the necessary math constants stored within the project (pi, e, ln(2), phi) to the higher precision, as the function may need one or more of these constants to provide an accurate value. (technically the calculator only needs pi and ln(2) internally. the other constants, including e and phi, are provided for user convenience.) there is complex number support for most functions. === algorithms + technical details === multiplication chooses between the standard, karatsuba, or FFT depending on the input size. division/sqrt uses newton-raphson's algorithm. exponentiation uses a combination of binary squaring and logarithms + Taylor series for exponential function. sin, cos, atan*, and exp use their respective taylor series to evaluate, with bit-burst and binary splitting techniques to speed up evaluation. tangent just does sine divided by cosine. ln uses a method based on the arithmetic-geometric mean function. this method needs both of the constants pi and ln(2) to work however. *the Taylor series for atan(x) only converges for |x| < 1, and it converges prohibitively slow for x with magnitude near to 1. therefore, this project will apply the half angle formula for arctan several times to reduce the input to a small enough number so that the Taylor series can be used. (atan(x) = 2*atan(x/(1+sqrt(1+x^2))) )
technical notes: each function will be categorized below in terms of how fast it is at high precision. take note of this list if you intend to do calculations in the thousands of digits or more. this list will only consider real number operations. respective complex number operations usually end up being a constant factor slower. S0: the fastest operations that exist. using them at high precision is perfectly fine. time complexity: O(n log(n)) or better - addition (+) - subtraction (-) - multiplication (*) S1: slightly slower than S0 but still more than usable for high precision. time complexity: O(n log(n)) - division (/) - square root (sqrt) - exponentiation (to integer powers only) - factorial (for relatively small integer inputs) S2: these functions usually require some sort of series to evaluate. they have been optimized but are noticeably slower than the previous two categories. still usable at high precision. time complexity: O(n log(n)^3) - exp - sinh - cosh - tanh - recalculating pi - recalculating e - recalculating ln(2) S3: these functions are fairly quick to calculate to high precision, however they are inherently more complicated to implement. time complexity: O(n log(n)^3) or O(n log(n)^2) with some constant factor - ln/log - atan S4: a constant factor slower than S2 functions. these still rely heavily on series expansions but are harder to optimize. time complexity: O(n log(n)^3) - sin - cos - tan - sec - csc - cot - asin - acos - asinh - acosh - atanh all functions described above fundamentally have quasi-linear or better runtime complexity, so they are able to scale well for high amounts of precision. the following algorithms will unfortunately not fall into this category, and may end up being prohibitively slow for large inputs and/or precision. S5: these functions are O(n^2) in the worst case but they have been deemed to be fast enough for moderate amounts of precision (30 ~ 400 digits) so they aren’t entirely unusable. they may be prohibitively slow for high amounts of precision though (> 800 digits). - factorial (for non integer number inputs) - erf S6: these functions may be very slow even for a modest amount of precision. - as of now no function is classified here, however the product and summation functions could possibly be here depending on what inputs they recieve. if numerical integration was in this calculator (possibly planned to be added eventually), it would be here too.