What's Happening?
Adhemerval Zanella has submitted a glibc patch series aimed at replacing IBM's double-precision `sin`, `cos`, and `sincos` routines with CORE-MATH implementations. The primary goal is to achieve correct rounding in all rounding modes, addressing inaccuracies
found in the current IBM code. The existing IBM routines often misround by one unit in the last place, particularly outside of round-to-nearest mode. Zanella's analysis of over four billion inputs revealed that about half of the results in directed rounding modes were off by one unit, and three-quarters of paired `sincos` results had at least one incorrect value. Even in round-to-nearest mode, the IBM functions misround hundreds of thousands of hard-to-round cases identified by CORE-MATH. The proposed CORE-MATH `sincos` function is built upon the new `sin` and `cos` code, ensuring bitwise identical results. This change is significant because compilers frequently optimize `sin` and `cos` of the same argument into a single `sincos` call, necessitating agreement among the three functions.
Why It's Important?
This proposed change in glibc is crucial for computational accuracy across various software applications, particularly those relying on precise mathematical calculations. The improved rounding accuracy in trigonometric functions directly impacts scientific computing, engineering simulations, and any field where floating-point precision is paramount. Inaccurate rounding, even by a small margin, can lead to cumulative errors in complex calculations, potentially affecting the reliability of models and analyses. While the new implementations show significant performance gains on slow paths (arguments from 2^27 up to the largest finite doubles), improving reciprocal throughput by five to eleven times, there are noted regressions in fast-path performance for certain architectures. For instance, `sin` is about 10 percent slower on AArch64, and `sincos` is about 28 percent slower there for inputs in approximately [-pi, pi]. This trade-off between accuracy and speed will be a key consideration for developers and system architects, as it could influence the performance of applications that frequently use these fast-path calculations.
What's Next?
The glibc patch series will undergo review and testing by the open-source community and glibc maintainers. If accepted, these CORE-MATH implementations will be integrated into future versions of glibc, becoming the standard for trigonometric function calculations. Developers and system administrators will need to monitor the adoption of these changes and assess their impact on existing software. The noted performance regressions on fast paths for specific architectures, such as AArch64, may prompt further optimization efforts or require developers to consider the implications for performance-critical applications. The series also aims to share one copy of tables among `sin`, `cos`, `sincos`, and x86_64 ifunc variants, and drops AVX-only variants, which no longer outperform SSE2 builds with software fused multiply-add. These architectural adjustments will also be part of the ongoing evaluation.
Beyond the Headlines
The pursuit of correctly rounded mathematical functions in core libraries like glibc highlights a fundamental challenge in computer science: balancing computational efficiency with absolute precision. While a single unit in the last place (ULP) error might seem negligible, its cumulative effect in iterative algorithms or large-scale simulations can lead to significant deviations from true values. This initiative underscores the continuous effort within the open-source community to refine foundational software components, ensuring that the underlying mathematical operations are as robust and accurate as possible. The discussion around performance trade-offs also reflects the complex interplay between hardware capabilities (like FMA and FMA4 variants) and software optimizations. This ongoing refinement of mathematical libraries is critical for the integrity of scientific research, financial modeling, and advanced technological development, where even minute inaccuracies can have substantial consequences.













