\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.0118953516307934663:\\
\;\;\;\;\log \left(e^{\frac{1 - \cos x}{\sin x}}\right)\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 2.2776287241343477 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{24}, {x}^{3}, \mathsf{fma}\left(\frac{1}{240}, {x}^{5}, \frac{1}{2} \cdot x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, \frac{1 \cdot 1 - {\left(\cos x\right)}^{2}}{1 - \cos x}, 1 \cdot 1\right)}}{\sin x}\\
\end{array}double f(double x) {
double r79494 = 1.0;
double r79495 = x;
double r79496 = cos(r79495);
double r79497 = r79494 - r79496;
double r79498 = sin(r79495);
double r79499 = r79497 / r79498;
return r79499;
}
double f(double x) {
double r79500 = 1.0;
double r79501 = x;
double r79502 = cos(r79501);
double r79503 = r79500 - r79502;
double r79504 = sin(r79501);
double r79505 = r79503 / r79504;
double r79506 = -0.011895351630793466;
bool r79507 = r79505 <= r79506;
double r79508 = exp(r79505);
double r79509 = log(r79508);
double r79510 = 2.2776287241343477e-05;
bool r79511 = r79505 <= r79510;
double r79512 = 0.041666666666666664;
double r79513 = 3.0;
double r79514 = pow(r79501, r79513);
double r79515 = 0.004166666666666667;
double r79516 = 5.0;
double r79517 = pow(r79501, r79516);
double r79518 = 0.5;
double r79519 = r79518 * r79501;
double r79520 = fma(r79515, r79517, r79519);
double r79521 = fma(r79512, r79514, r79520);
double r79522 = pow(r79500, r79513);
double r79523 = pow(r79502, r79513);
double r79524 = r79522 - r79523;
double r79525 = r79500 * r79500;
double r79526 = 2.0;
double r79527 = pow(r79502, r79526);
double r79528 = r79525 - r79527;
double r79529 = r79528 / r79503;
double r79530 = fma(r79502, r79529, r79525);
double r79531 = r79524 / r79530;
double r79532 = r79531 / r79504;
double r79533 = r79511 ? r79521 : r79532;
double r79534 = r79507 ? r79509 : r79533;
return r79534;
}




Bits error versus x
| Original | 29.8 |
|---|---|
| Target | 0.0 |
| Herbie | 0.7 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.011895351630793466Initial program 0.8
rmApplied add-log-exp1.0
if -0.011895351630793466 < (/ (- 1.0 (cos x)) (sin x)) < 2.2776287241343477e-05Initial program 60.0
Taylor expanded around 0 0.2
Simplified0.2
if 2.2776287241343477e-05 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.1
rmApplied flip3--1.2
Simplified1.2
rmApplied flip-+1.2
Simplified1.2
Final simplification0.7
herbie shell --seed 2020018 +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)))