\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.01854364127689415303601450091264268849045 \lor \neg \left(x \le 0.02331429387269752864786376278516399906948\right):\\
\;\;\;\;\frac{{e}^{\left(\log \left(1 - \cos x\right)\right)}}{\sin x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{24}, {x}^{3}, \mathsf{fma}\left(\frac{1}{240}, {x}^{5}, \frac{1}{2} \cdot x\right)\right)\\
\end{array}double f(double x) {
double r64435 = 1.0;
double r64436 = x;
double r64437 = cos(r64436);
double r64438 = r64435 - r64437;
double r64439 = sin(r64436);
double r64440 = r64438 / r64439;
return r64440;
}
double f(double x) {
double r64441 = x;
double r64442 = -0.018543641276894153;
bool r64443 = r64441 <= r64442;
double r64444 = 0.02331429387269753;
bool r64445 = r64441 <= r64444;
double r64446 = !r64445;
bool r64447 = r64443 || r64446;
double r64448 = exp(1.0);
double r64449 = 1.0;
double r64450 = cos(r64441);
double r64451 = r64449 - r64450;
double r64452 = log(r64451);
double r64453 = pow(r64448, r64452);
double r64454 = sin(r64441);
double r64455 = r64453 / r64454;
double r64456 = 0.041666666666666664;
double r64457 = 3.0;
double r64458 = pow(r64441, r64457);
double r64459 = 0.004166666666666667;
double r64460 = 5.0;
double r64461 = pow(r64441, r64460);
double r64462 = 0.5;
double r64463 = r64462 * r64441;
double r64464 = fma(r64459, r64461, r64463);
double r64465 = fma(r64456, r64458, r64464);
double r64466 = r64447 ? r64455 : r64465;
return r64466;
}




Bits error versus x
| Original | 30.7 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.018543641276894153 or 0.02331429387269753 < x Initial program 0.9
rmApplied add-exp-log0.9
rmApplied pow10.9
Applied log-pow0.9
Applied exp-prod1.0
Simplified1.0
if -0.018543641276894153 < x < 0.02331429387269753Initial program 59.9
Taylor expanded around 0 0.0
Simplified0.0
Final simplification0.5
herbie shell --seed 2019208 +o rules:numerics
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))