\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -2.76308119989467809 \cdot 10^{-4}:\\
\;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x}\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le -0.0:\\
\;\;\;\;\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{1}{\sin x} - \frac{\cos x}{\sin x}\\
\end{array}double f(double x) {
double r61439 = 1.0;
double r61440 = x;
double r61441 = cos(r61440);
double r61442 = r61439 - r61441;
double r61443 = sin(r61440);
double r61444 = r61442 / r61443;
return r61444;
}
double f(double x) {
double r61445 = 1.0;
double r61446 = x;
double r61447 = cos(r61446);
double r61448 = r61445 - r61447;
double r61449 = sin(r61446);
double r61450 = r61448 / r61449;
double r61451 = -0.0002763081199894678;
bool r61452 = r61450 <= r61451;
double r61453 = 3.0;
double r61454 = pow(r61445, r61453);
double r61455 = pow(r61447, r61453);
double r61456 = r61454 - r61455;
double r61457 = r61445 * r61447;
double r61458 = fma(r61447, r61447, r61457);
double r61459 = fma(r61445, r61445, r61458);
double r61460 = r61459 * r61449;
double r61461 = r61456 / r61460;
double r61462 = -0.0;
bool r61463 = r61450 <= r61462;
double r61464 = 0.041666666666666664;
double r61465 = pow(r61446, r61453);
double r61466 = 0.004166666666666667;
double r61467 = 5.0;
double r61468 = pow(r61446, r61467);
double r61469 = 0.5;
double r61470 = r61469 * r61446;
double r61471 = fma(r61466, r61468, r61470);
double r61472 = fma(r61464, r61465, r61471);
double r61473 = r61445 / r61449;
double r61474 = r61447 / r61449;
double r61475 = r61473 - r61474;
double r61476 = r61463 ? r61472 : r61475;
double r61477 = r61452 ? r61461 : r61476;
return r61477;
}




Bits error versus x
| Original | 30.3 |
|---|---|
| Target | 0.0 |
| Herbie | 0.7 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.0002763081199894678Initial program 1.0
rmApplied add-log-exp1.2
rmApplied clear-num1.2
Taylor expanded around inf 1.0
rmApplied flip3--1.1
Applied associate-/l/1.1
Simplified1.1
if -0.0002763081199894678 < (/ (- 1.0 (cos x)) (sin x)) < -0.0Initial program 60.3
Taylor expanded around 0 0.0
Simplified0.0
if -0.0 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.3
rmApplied div-sub1.5
Final simplification0.7
herbie shell --seed 2020062 +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)))