Fast Trigonometric Functions using the RLIBM Approach
Sehyeok Park, Santosh Nagarakatte
TL;DR
Problem: delivering correctly rounded trigonometric functions across multiple FP representations and rounding modes is difficult because range reduction hinges on precise handling of $2^t/\pi$. Approach: RLibm formulates the task as approximating the correctly rounded result and solves a linear program to enforce rounding constraints, extended to multiple representations via an $(n+2)$-bit representation with round-to-odd. Key contributions include FP- and integer-based range reduction strategies that preserve sufficient bits of $2^t/\pi$, plus a successful implementation for sin, cos, and tan that is fast and correctly rounded from 10- to 32-bit representations. Significance: the work yields portable, high-precision trig functions competitive with mainstream libraries, with practical impact for multi-representation computing and future GPU support.
Abstract
This paper describes our experience developing polynomial approximations for trigonometric functions that produce correctly rounded results for multiple representations and rounding modes using the RLIBM approach. A key challenge with trigonometric functions concerns range reduction with "pi", which reduces a given input in the domain of a 32-bit float to a small domain. Any rounding error in the value of "pi" is amplified during range reduction, which can result in wrong results. We describe our experience implementing fast range reduction techniques that maintain a large number of bits of "pi" both with floating-point and integer computations. The resulting implementations for trigonometric functions are fast and produce correctly rounded results for all inputs for multiple representations up to 32-bits with a single implementation.
