(math)=
:hidden: true log stdfix
The highest priority is to be as accurate as possible, according to the C and IEEE 754 standards. By default, we will aim to be correctly rounded for all rounding modes. The current rounding mode of the floating point environment is used to perform computations and produce the final results.
Our next requirement is that the outputs are consistent across all platforms. Notice that the consistency requirement will be satisfied automatically if the implementation is correctly rounded.
Our last requirement for the implementations is to have good and predicable performance:
libc implementations.For other use cases that have strict requirements on the code size, memory footprint, or latency, such as embedded systems, we will aim to be as accurate as possible within the memory or latency budgets, and consistent across all platforms.
C23 and POSIX.1-2024 header status tables: {doc}../headers/math
To check math functions enabled for Linux:
To check math functions enabled for Windows:
To check math functions enabled for macOS:
To check math functions enabled for GPU:
To check math functions enabled for embedded system:
% TODO(lntue): Add a new page to discuss about the algorithms used in the % implementations and include the link here.
LIBC_MATH_SKIP_ACCURATE_PASS, LIBC_MATH_INTERMEDIATE_COMP_IN_FLOAT, LIBC_MATH_SMALL_TABLES, LIBC_MATH_NO_ERRNO, and LIBC_MATH_NO_EXCEPT.+------------------------+-------------+---------------+-----------------------------------------------------------------------------------+ | Function | Test Method | ULP Tolerance | Max ULP Distance | | | | +--------------------+--------------------+--------------------+--------------------+ | | | | LLVM libc | LLVM libc | CUDA Math | HIP Math | | | | | (AMDGPU) | (CUDA) | (CUDA) | (AMDGPU) | +========================+=============+===============+====================+====================+====================+====================+ | acos | Randomized | 4 | 6 (FAILED) | 6 (FAILED) | 1 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | acosf | Exhaustive | 4 | 1 | 1 | 1 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | acosf16 | Exhaustive | 2 | 1 | 1 | | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | acoshf | Exhaustive | 4 | 1 | 1 | 2 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | acoshf16 | Exhaustive | 2 | 0 | 0 | | 0 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | acospif16 | Exhaustive | 2 | 0 | 0 | | | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | asin | Randomized | 4 | 6 (FAILED) | 6 (FAILED) | 2 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | asinf | Exhaustive | 4 | 1 | 1 | 1 | 3 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | asinf16 | Exhaustive | 2 | 0 | 0 | | 2 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | asinhf | Exhaustive | 4 | 1 | 1 | 2 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | asinhf16 | Exhaustive | 2 | 1 | 1 | | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | atanf | Exhaustive | 5 | 0 | 0 | 1 | 2 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | atanf16 | Exhaustive | 2 | 1 | 1 | | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | atan2f | Randomized | 6 | 1 | 1 | 2 | 3 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | atanhf | Exhaustive | 5 | 0 | 0 | 3 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | atanhf16 | Exhaustive | 2 | 0 | 0 | | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | cbrt | Randomized | 2 | 1 | 1 | 1 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | cbrtf | Exhaustive | 2 | 0 | 0 | 1 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | cos | Randomized | 4 | 1 | 1 | 2 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | cosf | Exhaustive | 4 | 1 | 1 | 2 | 2 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | cosf16 | Exhaustive | 2 | 1 | 1 | | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | coshf | Exhaustive | 4 | 0 | 0 | 2 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | coshf16 | Exhaustive | 2 | 1 | 0 | | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | cospif | Exhaustive | 4 | 0 | 0 | 1 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | cospif16 | Exhaustive | 2 | 0 | 0 | | | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | erff | Exhaustive | 16 | 0 | 0 | 1 | 2 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | exp | Randomized | 3 | 1 | 1 | 1 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | expf | Exhaustive | 3 | 0 | 0 | 2 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | expf16 | Exhaustive | 2 | 1 | 1 | | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | exp10 | Randomized | 3 | 1 | 1 | 1 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | exp10f | Exhaustive | 3 | 0 | 0 | 2 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | exp10f16 | Exhaustive | 2 | 1 | 1 | | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | exp2 | Randomized | 3 | 1 | 1 | 1 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | exp2f | Exhaustive | 3 | 1 | 1 | 2 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | exp2f16 | Exhaustive | 2 | 1 | 1 | | 0 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | expm1 | Randomized | 3 | 0 | 0 | 1 | 2 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | expm1f | Exhaustive | 3 | 1 | 1 | 1 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | expm1f16 | Exhaustive | 2 | 1 | 1 | | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | hypot | Randomized | 4 | 0 | 0 | 2 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | hypotf | Randomized | 4 | 0 | 0 | 1 | 2 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | hypotf16 | Exhaustive | 2 | 0 | 0 | | | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | log | Randomized | 3 | 1 | 1 | 1 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | logf | Exhaustive | 3 | 1 | 1 | 1 | 2 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | logf16 | Exhaustive | 2 | 1 | 1 | | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | log10 | Randomized | 3 | 1 | 1 | 1 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | log10f | Exhaustive | 3 | 1 | 1 | 2 | 2 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | log10f16 | Exhaustive | 2 | 1 | 1 | | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | log1p | Randomized | 2 | 1 | 1 | 1 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | log1pf | Exhaustive | 2 | 1 | 1 | 1 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | log2 | Randomized | 3 | 1 | 1 | 1 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | log2f | Exhaustive | 3 | 0 | 0 | 1 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | log2f16 | Exhaustive | 2 | 1 | 1 | | 0 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | powf (integer exp.) | Randomized | 16 | 0 | 0 | 2 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | powf (real exp.) | Randomized | 16 | 0 | 0 | 2 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | sin | Randomized | 4 | 1 | 1 | 1 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | sinf | Exhaustive | 4 | 1 | 1 | 1 | 2 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | sinf16 | Exhaustive | 2 | 1 | 1 | | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | sincos (cos part) | Randomized | 4 | 1 | 1 | 2 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | sincos (sin part) | Randomized | 4 | 1 | 1 | 1 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | sincosf (cos part) | Exhaustive | 4 | 1 | 1 | 2 | 2 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | sincosf (sin part) | Exhaustive | 4 | 1 | 1 | 1 | 2 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | sinhf | Exhaustive | 4 | 1 | 1 | 3 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | sinhf16 | Exhaustive | 2 | 1 | 1 | | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | sinpif | Exhaustive | 4 | 0 | 0 | 1 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | sinpif16 | Exhaustive | 2 | 0 | 0 | | | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | tan | Randomized | 5 | 2 | 2 | 2 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | tanf | Exhaustive | 5 | 0 | 0 | 3 | 2 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | tanf16 | Exhaustive | 2 | 1 | 1 | | 2 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | tanhf | Exhaustive | 5 | 0 | 0 | 2 | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | tanhf16 | Exhaustive | 2 | 0 | 0 | | 1 | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | tanpif | Exhaustive | 6 | 0 | 0 | | | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+ | tanpif16 | Exhaustive | 2 | 1 | 1 | | | +------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
Notes:
32 samples. This method is used for functions with larger input spaces, such as single-precision bivariate and double-precision functions.+--------------+-------------------------------+-------------------------------+-------------------------------------+----------------------------------------------------------------------+ | <Func> | Reciprocal throughput (clk) | Latency (clk) | Testing ranges | Testing configuration | | +-----------+-------------------+-----------+-------------------+ +-------------+-------------------------+--------------+---------------+ | | LLVM libc | Reference (glibc) | LLVM libc | Reference (glibc) | | CPU | OS | Compiler | Special flags | +==============+===========+===================+===========+===================+=====================================+=============+=========================+==============+===============+ | acosf | 24 | 29 | 62 | 77 | :math:`[-1, 1]` | Ryzen 1700 | Ubuntu 22.04 LTS x86_64 | Clang 14.0.0 | FMA | +--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | acoshf | 18 | 26 | 73 | 74 | :math:`[1, 21]` | Ryzen 1700 | Ubuntu 22.04 LTS x86_64 | Clang 14.0.0 | FMA | +--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | asinf | 23 | 27 | 62 | 62 | :math:`[-1, 1]` | Ryzen 1700 | Ubuntu 22.04 LTS x86_64 | Clang 14.0.0 | FMA | +--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | asinhf | 21 | 39 | 77 | 91 | :math:`[-10, 10]` | Ryzen 1700 | Ubuntu 22.04 LTS x86_64 | Clang 14.0.0 | FMA | +--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | atanf | 27 | 29 | 79 | 68 | :math:`[-10, 10]` | Ryzen 1700 | Ubuntu 22.04 LTS x86_64 | Clang 14.0.0 | FMA | +--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | atanhf | 18 | 66 | 68 | 133 | :math:`[-1, 1]` | Ryzen 1700 | Ubuntu 22.04 LTS x86_64 | Clang 14.0.0 | FMA | +--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | cosf | 13 | 32 | 53 | 59 | :math:`[0, 2\pi]` | Ryzen 1700 | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | FMA | +--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | coshf | 14 | 20 | 50 | 48 | :math:`[-10, 10]` | Ryzen 1700 | Ubuntu 22.04 LTS x86_64 | Clang 14.0.0 | FMA | +--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | expf | 9 | 7 | 44 | 38 | :math:`[-10, 10]` | Ryzen 1700 | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | FMA | +--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | exp10f | 10 | 8 | 40 | 38 | :math:`[-10, 10]` | Ryzen 1700 | Ubuntu 22.04 LTS x86_64 | Clang 14.0.0 | FMA | +--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | exp2f | 9 | 6 | 35 | 31 | :math:`[-10, 10]` | Ryzen 1700 | Ubuntu 22.04 LTS x86_64 | Clang 14.0.0 | FMA | +--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | expm1f | 9 | 44 | 42 | 121 | :math:`[-10, 10]` | Ryzen 1700 | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | FMA | +--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | fmodf | 73 | 263 | - | - | [MIN_NORMAL, MAX_NORMAL] | i5 mobile | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | | | +-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | | 9 | 11 | - | - | [0, MAX_SUBNORMAL] | i5 mobile | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | | +--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | fmod | 595 | 3297 | - | - | [MIN_NORMAL, MAX_NORMAL] | i5 mobile | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | | | +-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | | 14 | 13 | - | - | [0, MAX_SUBNORMAL] | i5 mobile | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | | +--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | hypotf | 25 | 15 | 64 | 49 | :math:`[-10, 10] \times [-10, 10]` | Ryzen 1700 | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | | +--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | logf | 12 | 10 | 56 | 46 | :math:`[e^{-1}, e]` | Ryzen 1700 | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | FMA | +--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | log10f | 9 | 17 | 35 | 48 | :math:`[e^{-1}, e]` | Ryzen 5900X | Ubuntu 22.04 LTS x86_64 | Clang 15.0.6 | FMA | +--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | log1pf | 16 | 33 | 61 | 97 | :math:`[e^{-0.5} - 1, e^{0.5} - 1]` | Ryzen 1700 | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | FMA | +--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | log2f | 13 | 10 | 57 | 46 | :math:`[e^{-1}, e]` | Ryzen 1700 | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | FMA | +--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | sinf | 12 | 25 | 51 | 57 | :math:`[-\pi, \pi]` | Ryzen 1700 | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | FMA | +--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | sincosf | 19 | 30 | 57 | 68 | :math:`[-\pi, \pi]` | Ryzen 1700 | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | FMA | +--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | sinhf | 13 | 63 | 48 | 137 | :math:`[-10, 10]` | Ryzen 1700 | Ubuntu 22.04 LTS x86_64 | Clang 14.0.0 | FMA | +--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | tanf | 16 | 50 | 61 | 107 | :math:`[-\pi, \pi]` | Ryzen 1700 | Ubuntu 22.04 LTS x86_64 | Clang 14.0.0 | FMA | +--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+ | tanhf | 13 | 55 | 57 | 123 | :math:`[-10, 10]` | Ryzen 1700 | Ubuntu 22.04 LTS x86_64 | Clang 14.0.0 | FMA | +--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
logstdfix../headers/stdfix