\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.0190087476176216581:\\
\;\;\;\;\log \left(\mathsf{expm1}\left(\mathsf{log1p}\left(e^{\frac{1 - \cos x}{\sin x}}\right)\right)\right)\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 4.47527012274922384 \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{\log \left(e^{1 - \cos x}\right)}{\sin x}\\
\end{array}double f(double x) {
double r41513 = 1.0;
double r41514 = x;
double r41515 = cos(r41514);
double r41516 = r41513 - r41515;
double r41517 = sin(r41514);
double r41518 = r41516 / r41517;
return r41518;
}
double f(double x) {
double r41519 = 1.0;
double r41520 = x;
double r41521 = cos(r41520);
double r41522 = r41519 - r41521;
double r41523 = sin(r41520);
double r41524 = r41522 / r41523;
double r41525 = -0.019008747617621658;
bool r41526 = r41524 <= r41525;
double r41527 = exp(r41524);
double r41528 = log1p(r41527);
double r41529 = expm1(r41528);
double r41530 = log(r41529);
double r41531 = 4.475270122749224e-05;
bool r41532 = r41524 <= r41531;
double r41533 = 0.041666666666666664;
double r41534 = 3.0;
double r41535 = pow(r41520, r41534);
double r41536 = 0.004166666666666667;
double r41537 = 5.0;
double r41538 = pow(r41520, r41537);
double r41539 = 0.5;
double r41540 = r41539 * r41520;
double r41541 = fma(r41536, r41538, r41540);
double r41542 = fma(r41533, r41535, r41541);
double r41543 = exp(r41522);
double r41544 = log(r41543);
double r41545 = r41544 / r41523;
double r41546 = r41532 ? r41542 : r41545;
double r41547 = r41526 ? r41530 : r41546;
return r41547;
}




Bits error versus x
| Original | 30.2 |
|---|---|
| Target | 0 |
| Herbie | 0.7 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.019008747617621658Initial program 0.8
rmApplied add-log-exp0.8
rmApplied expm1-log1p-u0.9
if -0.019008747617621658 < (/ (- 1.0 (cos x)) (sin x)) < 4.475270122749224e-05Initial program 59.6
Taylor expanded around 0 0.4
Simplified0.4
if 4.475270122749224e-05 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.0
rmApplied add-log-exp1.2
Applied add-log-exp1.2
Applied diff-log1.4
Simplified1.2
Final simplification0.7
herbie shell --seed 2020021 +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)))