\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.020168669770568547:\\
\;\;\;\;\frac{\sin x \cdot \left(1 - \cos x\right)}{\sin x \cdot \sin x}\\
\mathbf{elif}\;x \le 0.0257297152168081099:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin x} - \frac{\cos x}{\sin x}\\
\end{array}double f(double x) {
double r47328 = 1.0;
double r47329 = x;
double r47330 = cos(r47329);
double r47331 = r47328 - r47330;
double r47332 = sin(r47329);
double r47333 = r47331 / r47332;
return r47333;
}
double f(double x) {
double r47334 = x;
double r47335 = -0.020168669770568547;
bool r47336 = r47334 <= r47335;
double r47337 = sin(r47334);
double r47338 = 1.0;
double r47339 = cos(r47334);
double r47340 = r47338 - r47339;
double r47341 = r47337 * r47340;
double r47342 = r47337 * r47337;
double r47343 = r47341 / r47342;
double r47344 = 0.02572971521680811;
bool r47345 = r47334 <= r47344;
double r47346 = 0.041666666666666664;
double r47347 = 3.0;
double r47348 = pow(r47334, r47347);
double r47349 = r47346 * r47348;
double r47350 = 0.004166666666666667;
double r47351 = 5.0;
double r47352 = pow(r47334, r47351);
double r47353 = r47350 * r47352;
double r47354 = 0.5;
double r47355 = r47354 * r47334;
double r47356 = r47353 + r47355;
double r47357 = r47349 + r47356;
double r47358 = r47338 / r47337;
double r47359 = r47339 / r47337;
double r47360 = r47358 - r47359;
double r47361 = r47345 ? r47357 : r47360;
double r47362 = r47336 ? r47343 : r47361;
return r47362;
}




Bits error versus x
Results
| Original | 30.1 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.020168669770568547Initial program 0.9
rmApplied div-sub1.1
rmApplied frac-sub1.0
Simplified1.0
if -0.020168669770568547 < x < 0.02572971521680811Initial program 59.8
Taylor expanded around 0 0.0
if 0.02572971521680811 < x Initial program 0.9
rmApplied div-sub1.1
Final simplification0.5
herbie shell --seed 2020045
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))