\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.01783437632320246032935351365722453920171:\\
\;\;\;\;\frac{1}{\frac{\sin x}{1 - \cos x}}\\
\mathbf{elif}\;x \le 0.02134032948837288543031398546645505120978:\\
\;\;\;\;0.04166666666666662965923251249478198587894 \cdot {x}^{3} + \left(0.004166666666666624108117389368999283760786 \cdot {x}^{5} + 0.5 \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\left(\cos x \cdot \frac{{1}^{3} + {\left(\cos x\right)}^{3}}{1 \cdot \left(1 - \cos x\right) + {\left(\cos x\right)}^{2}} + 1 \cdot 1\right) \cdot \sin x}\\
\end{array}double f(double x) {
double r21321 = 1.0;
double r21322 = x;
double r21323 = cos(r21322);
double r21324 = r21321 - r21323;
double r21325 = sin(r21322);
double r21326 = r21324 / r21325;
return r21326;
}
double f(double x) {
double r21327 = x;
double r21328 = -0.01783437632320246;
bool r21329 = r21327 <= r21328;
double r21330 = 1.0;
double r21331 = sin(r21327);
double r21332 = 1.0;
double r21333 = cos(r21327);
double r21334 = r21332 - r21333;
double r21335 = r21331 / r21334;
double r21336 = r21330 / r21335;
double r21337 = 0.021340329488372885;
bool r21338 = r21327 <= r21337;
double r21339 = 0.04166666666666663;
double r21340 = 3.0;
double r21341 = pow(r21327, r21340);
double r21342 = r21339 * r21341;
double r21343 = 0.004166666666666624;
double r21344 = 5.0;
double r21345 = pow(r21327, r21344);
double r21346 = r21343 * r21345;
double r21347 = 0.5;
double r21348 = r21347 * r21327;
double r21349 = r21346 + r21348;
double r21350 = r21342 + r21349;
double r21351 = pow(r21332, r21340);
double r21352 = pow(r21333, r21340);
double r21353 = r21351 - r21352;
double r21354 = r21351 + r21352;
double r21355 = r21332 * r21334;
double r21356 = 2.0;
double r21357 = pow(r21333, r21356);
double r21358 = r21355 + r21357;
double r21359 = r21354 / r21358;
double r21360 = r21333 * r21359;
double r21361 = r21332 * r21332;
double r21362 = r21360 + r21361;
double r21363 = r21362 * r21331;
double r21364 = r21353 / r21363;
double r21365 = r21338 ? r21350 : r21364;
double r21366 = r21329 ? r21336 : r21365;
return r21366;
}




Bits error versus x
Results
| Original | 30.2 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.01783437632320246Initial program 0.9
rmApplied clear-num1.0
if -0.01783437632320246 < x < 0.021340329488372885Initial program 59.8
rmApplied flip3--59.8
Applied associate-/l/59.8
Simplified59.8
Taylor expanded around 0 0.0
if 0.021340329488372885 < x Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
rmApplied flip3-+1.0
Simplified1.0
Simplified1.0
Final simplification0.5
herbie shell --seed 2019297
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))