maths.fast_inverse_sqrt ======================= .. py:module:: maths.fast_inverse_sqrt .. autoapi-nested-parse:: Fast inverse square root (1/sqrt(x)) using the Quake III algorithm. Reference: https://en.wikipedia.org/wiki/Fast_inverse_square_root Accuracy: https://en.wikipedia.org/wiki/Fast_inverse_square_root#Accuracy Functions --------- .. autoapisummary:: maths.fast_inverse_sqrt.fast_inverse_sqrt Module Contents --------------- .. py:function:: fast_inverse_sqrt(number: float) -> float Compute the fast inverse square root of a floating-point number using the famous Quake III algorithm. :param float number: Input number for which to calculate the inverse square root. :return float: The fast inverse square root of the input number. Example: >>> fast_inverse_sqrt(10) 0.3156857923527257 >>> fast_inverse_sqrt(4) 0.49915357479239103 >>> fast_inverse_sqrt(4.1) 0.4932849504615651 >>> fast_inverse_sqrt(0) Traceback (most recent call last): ... ValueError: Input must be a positive number. >>> fast_inverse_sqrt(-1) Traceback (most recent call last): ... ValueError: Input must be a positive number. >>> from math import isclose, sqrt >>> all(isclose(fast_inverse_sqrt(i), 1 / sqrt(i), rel_tol=0.00132) ... for i in range(50, 60)) True