\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.0391915361306189591328319465901586227119:\\
\;\;\;\;\frac{1}{1 + \cos x} \cdot \left(\left(\left(1 + \cos x\right) \cdot \left(1 - \cos x\right)\right) \cdot \frac{1}{\sin x}\right)\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 5.238158504786694352056697354669267951977 \cdot 10^{-4}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{240}, {x}^{5}, \mathsf{fma}\left({x}^{3}, \frac{1}{24}, x \cdot \frac{1}{2}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left({\left(e^{\frac{1}{\sin x}}\right)}^{\left(1 - \cos x\right)}\right)\\
\end{array}double f(double x) {
double r70430 = 1.0;
double r70431 = x;
double r70432 = cos(r70431);
double r70433 = r70430 - r70432;
double r70434 = sin(r70431);
double r70435 = r70433 / r70434;
return r70435;
}
double f(double x) {
double r70436 = 1.0;
double r70437 = x;
double r70438 = cos(r70437);
double r70439 = r70436 - r70438;
double r70440 = sin(r70437);
double r70441 = r70439 / r70440;
double r70442 = -0.03919153613061896;
bool r70443 = r70441 <= r70442;
double r70444 = 1.0;
double r70445 = r70436 + r70438;
double r70446 = r70444 / r70445;
double r70447 = r70445 * r70439;
double r70448 = r70444 / r70440;
double r70449 = r70447 * r70448;
double r70450 = r70446 * r70449;
double r70451 = 0.0005238158504786694;
bool r70452 = r70441 <= r70451;
double r70453 = 0.004166666666666667;
double r70454 = 5.0;
double r70455 = pow(r70437, r70454);
double r70456 = 3.0;
double r70457 = pow(r70437, r70456);
double r70458 = 0.041666666666666664;
double r70459 = 0.5;
double r70460 = r70437 * r70459;
double r70461 = fma(r70457, r70458, r70460);
double r70462 = fma(r70453, r70455, r70461);
double r70463 = exp(r70448);
double r70464 = pow(r70463, r70439);
double r70465 = log(r70464);
double r70466 = r70452 ? r70462 : r70465;
double r70467 = r70443 ? r70450 : r70466;
return r70467;
}




Bits error versus x
| Original | 30.3 |
|---|---|
| Target | 0.0 |
| Herbie | 1.0 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.03919153613061896Initial program 0.7
rmApplied clear-num0.8
rmApplied flip--1.2
Applied associate-/r/1.3
Applied add-cube-cbrt1.3
Applied times-frac1.3
Simplified0.9
Simplified0.9
if -0.03919153613061896 < (/ (- 1.0 (cos x)) (sin x)) < 0.0005238158504786694Initial program 59.2
rmApplied clear-num59.2
Taylor expanded around 0 0.9
Simplified0.9
if 0.0005238158504786694 < (/ (- 1.0 (cos x)) (sin x)) Initial program 0.9
rmApplied clear-num1.0
rmApplied add-log-exp1.0
Simplified1.1
Final simplification1.0
herbie shell --seed 2019194 +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)))