\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.02298820551471121229059058066468423930928 \lor \neg \left(x \le 0.01805643764531137188122933423528593266383\right):\\
\;\;\;\;\frac{1 - \cos x}{\sin x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{24}, {x}^{3}, \mathsf{fma}\left({x}^{5}, \frac{1}{240}, x \cdot \frac{1}{2}\right)\right)\\
\end{array}double f(double x) {
double r45426 = 1.0;
double r45427 = x;
double r45428 = cos(r45427);
double r45429 = r45426 - r45428;
double r45430 = sin(r45427);
double r45431 = r45429 / r45430;
return r45431;
}
double f(double x) {
double r45432 = x;
double r45433 = -0.022988205514711212;
bool r45434 = r45432 <= r45433;
double r45435 = 0.018056437645311372;
bool r45436 = r45432 <= r45435;
double r45437 = !r45436;
bool r45438 = r45434 || r45437;
double r45439 = 1.0;
double r45440 = cos(r45432);
double r45441 = r45439 - r45440;
double r45442 = sin(r45432);
double r45443 = r45441 / r45442;
double r45444 = 0.041666666666666664;
double r45445 = 3.0;
double r45446 = pow(r45432, r45445);
double r45447 = 5.0;
double r45448 = pow(r45432, r45447);
double r45449 = 0.004166666666666667;
double r45450 = 0.5;
double r45451 = r45432 * r45450;
double r45452 = fma(r45448, r45449, r45451);
double r45453 = fma(r45444, r45446, r45452);
double r45454 = r45438 ? r45443 : r45453;
return r45454;
}




Bits error versus x
| Original | 30.7 |
|---|---|
| Target | 0.0 |
| Herbie | 0.4 |
if x < -0.022988205514711212 or 0.018056437645311372 < x Initial program 0.9
rmApplied *-un-lft-identity0.9
Applied *-un-lft-identity0.9
Applied times-frac0.9
Simplified0.9
if -0.022988205514711212 < x < 0.018056437645311372Initial program 59.8
Taylor expanded around 0 0.0
Simplified0.0
Final simplification0.4
herbie shell --seed 2019195 +o rules:numerics
(FPCore (x)
:name "tanhf (example 3.4)"
:herbie-expected 2
:herbie-target
(tan (/ x 2.0))
(/ (- 1.0 (cos x)) (sin x)))