\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.02066634150666165486986969312965811695904:\\
\;\;\;\;\frac{\frac{1 \cdot \left(1 \cdot 1\right) - \left(\cos x \cdot \cos x\right) \cdot \cos x}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x}\\
\mathbf{elif}\;x \le 0.02306599559720158912345944202115788357332:\\
\;\;\;\;\mathsf{fma}\left({x}^{5}, \frac{1}{240}, x \cdot \left(\frac{1}{2} + \left(x \cdot x\right) \cdot \frac{1}{24}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{\log \left(\frac{1 \cdot \left(1 \cdot 1\right) - \log \left(e^{\cos x \cdot \cos x}\right) \cdot \cos x}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}\right)}}{\sin x}\\
\end{array}double f(double x) {
double r2876430 = 1.0;
double r2876431 = x;
double r2876432 = cos(r2876431);
double r2876433 = r2876430 - r2876432;
double r2876434 = sin(r2876431);
double r2876435 = r2876433 / r2876434;
return r2876435;
}
double f(double x) {
double r2876436 = x;
double r2876437 = -0.020666341506661655;
bool r2876438 = r2876436 <= r2876437;
double r2876439 = 1.0;
double r2876440 = r2876439 * r2876439;
double r2876441 = r2876439 * r2876440;
double r2876442 = cos(r2876436);
double r2876443 = r2876442 * r2876442;
double r2876444 = r2876443 * r2876442;
double r2876445 = r2876441 - r2876444;
double r2876446 = r2876439 + r2876442;
double r2876447 = fma(r2876442, r2876446, r2876440);
double r2876448 = r2876445 / r2876447;
double r2876449 = sin(r2876436);
double r2876450 = r2876448 / r2876449;
double r2876451 = 0.02306599559720159;
bool r2876452 = r2876436 <= r2876451;
double r2876453 = 5.0;
double r2876454 = pow(r2876436, r2876453);
double r2876455 = 0.004166666666666667;
double r2876456 = 0.5;
double r2876457 = r2876436 * r2876436;
double r2876458 = 0.041666666666666664;
double r2876459 = r2876457 * r2876458;
double r2876460 = r2876456 + r2876459;
double r2876461 = r2876436 * r2876460;
double r2876462 = fma(r2876454, r2876455, r2876461);
double r2876463 = exp(r2876443);
double r2876464 = log(r2876463);
double r2876465 = r2876464 * r2876442;
double r2876466 = r2876441 - r2876465;
double r2876467 = r2876466 / r2876447;
double r2876468 = log(r2876467);
double r2876469 = exp(r2876468);
double r2876470 = r2876469 / r2876449;
double r2876471 = r2876452 ? r2876462 : r2876470;
double r2876472 = r2876438 ? r2876450 : r2876471;
return r2876472;
}




Bits error versus x
| Original | 30.2 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.020666341506661655Initial program 0.9
rmApplied flip3--1.0
Simplified1.0
Simplified1.0
if -0.020666341506661655 < x < 0.02306599559720159Initial program 59.9
Taylor expanded around 0 0.0
Simplified0.0
if 0.02306599559720159 < x Initial program 0.9
rmApplied flip3--1.0
Simplified1.0
Simplified1.0
rmApplied add-exp-log1.0
Applied add-exp-log1.0
Applied div-exp1.0
Simplified1.0
rmApplied add-log-exp1.1
Final simplification0.5
herbie shell --seed 2019174 +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)))