\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.0236105927013185481:\\
\;\;\;\;\frac{1}{\sin x} - \frac{\cos x}{\sin x}\\
\mathbf{elif}\;x \le 0.0199371016091038876:\\
\;\;\;\;\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}:\\
\;\;\;\;\log \left(e^{\frac{1}{\frac{\sin x}{1 - \cos x}}}\right)\\
\end{array}double f(double x) {
double r67425 = 1.0;
double r67426 = x;
double r67427 = cos(r67426);
double r67428 = r67425 - r67427;
double r67429 = sin(r67426);
double r67430 = r67428 / r67429;
return r67430;
}
double f(double x) {
double r67431 = x;
double r67432 = -0.023610592701318548;
bool r67433 = r67431 <= r67432;
double r67434 = 1.0;
double r67435 = sin(r67431);
double r67436 = r67434 / r67435;
double r67437 = cos(r67431);
double r67438 = r67437 / r67435;
double r67439 = r67436 - r67438;
double r67440 = 0.019937101609103888;
bool r67441 = r67431 <= r67440;
double r67442 = 0.041666666666666664;
double r67443 = 3.0;
double r67444 = pow(r67431, r67443);
double r67445 = 0.004166666666666667;
double r67446 = 5.0;
double r67447 = pow(r67431, r67446);
double r67448 = 0.5;
double r67449 = r67448 * r67431;
double r67450 = fma(r67445, r67447, r67449);
double r67451 = fma(r67442, r67444, r67450);
double r67452 = 1.0;
double r67453 = r67434 - r67437;
double r67454 = r67435 / r67453;
double r67455 = r67452 / r67454;
double r67456 = exp(r67455);
double r67457 = log(r67456);
double r67458 = r67441 ? r67451 : r67457;
double r67459 = r67433 ? r67439 : r67458;
return r67459;
}




Bits error versus x
| Original | 30.1 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.023610592701318548Initial program 0.9
rmApplied div-sub1.1
if -0.023610592701318548 < x < 0.019937101609103888Initial program 59.7
Taylor expanded around 0 0.0
Simplified0.0
if 0.019937101609103888 < x Initial program 0.8
rmApplied add-log-exp0.9
rmApplied clear-num1.0
Final simplification0.5
herbie shell --seed 2020057 +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)))