cengal.math.algebra.fast_algorithms.versions.v_0.fast_algorithms

Module Docstring Docstrings: http://www.python.org/dev/peps/pep-0257/

 1#!/usr/bin/env python
 2# coding=utf-8
 3
 4# Copyright © 2012-2024 ButenkoMS. All rights reserved. Contacts: <gtalk@butenkoms.space>
 5# 
 6# Licensed under the Apache License, Version 2.0 (the "License");
 7# you may not use this file except in compliance with the License.
 8# You may obtain a copy of the License at
 9# 
10#     http://www.apache.org/licenses/LICENSE-2.0
11# 
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17
18"""
19Module Docstring
20Docstrings: http://www.python.org/dev/peps/pep-0257/
21"""
22
23__author__ = "ButenkoMS <gtalk@butenkoms.space>"
24__copyright__ = "Copyright © 2012-2024 ButenkoMS. All rights reserved. Contacts: <gtalk@butenkoms.space>"
25__credits__ = ["ButenkoMS <gtalk@butenkoms.space>", ]
26__license__ = "Apache License, Version 2.0"
27__version__ = "4.4.1"
28__maintainer__ = "ButenkoMS <gtalk@butenkoms.space>"
29__email__ = "gtalk@butenkoms.space"
30# __status__ = "Prototype"
31__status__ = "Development"
32# __status__ = "Production"
33
34
35from cengal.math.numbers import RationalNumber
36from cengal.data_manipulation.conversion.bit_cast_like import bit_cast__uint32_to_float, bit_cast__float_to_uint32
37
38
39def rsqrt(x: RationalNumber) -> float:
40    """Fast inverse square root
41    https://en.wikipedia.org/wiki/Fast_inverse_square_root
42
43    Args:
44        x (RationalNumber): _description_
45
46    Returns:
47        float: _description_
48    """
49    if isinstance(x, int):
50        x = float(x)
51    
52    y = bit_cast__uint32_to_float(0x5f3759df - (bit_cast__float_to_uint32(x) >> 1))
53    return y * (1.5 - (x * 0.5 * y * y))
def rsqrt(x: Union[int, float]) -> float:
40def rsqrt(x: RationalNumber) -> float:
41    """Fast inverse square root
42    https://en.wikipedia.org/wiki/Fast_inverse_square_root
43
44    Args:
45        x (RationalNumber): _description_
46
47    Returns:
48        float: _description_
49    """
50    if isinstance(x, int):
51        x = float(x)
52    
53    y = bit_cast__uint32_to_float(0x5f3759df - (bit_cast__float_to_uint32(x) >> 1))
54    return y * (1.5 - (x * 0.5 * y * y))

Fast inverse square root https://en.wikipedia.org/wiki/Fast_inverse_square_root

Args: x (RationalNumber): _description_

Returns: float: _description_