\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.0195414650842071873:\\
\;\;\;\;\frac{1 - \cos x}{\sin x}\\
\mathbf{elif}\;x \le 0.023267676544555443:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{{e}^{\left(\log \left(1 - \cos x\right)\right)}}{\sin x}\\
\end{array}double f(double x) {
double r59334 = 1.0;
double r59335 = x;
double r59336 = cos(r59335);
double r59337 = r59334 - r59336;
double r59338 = sin(r59335);
double r59339 = r59337 / r59338;
return r59339;
}
double f(double x) {
double r59340 = x;
double r59341 = -0.019541465084207187;
bool r59342 = r59340 <= r59341;
double r59343 = 1.0;
double r59344 = cos(r59340);
double r59345 = r59343 - r59344;
double r59346 = sin(r59340);
double r59347 = r59345 / r59346;
double r59348 = 0.023267676544555443;
bool r59349 = r59340 <= r59348;
double r59350 = 0.041666666666666664;
double r59351 = 3.0;
double r59352 = pow(r59340, r59351);
double r59353 = r59350 * r59352;
double r59354 = 0.004166666666666667;
double r59355 = 5.0;
double r59356 = pow(r59340, r59355);
double r59357 = r59354 * r59356;
double r59358 = 0.5;
double r59359 = r59358 * r59340;
double r59360 = r59357 + r59359;
double r59361 = r59353 + r59360;
double r59362 = exp(1.0);
double r59363 = log(r59345);
double r59364 = pow(r59362, r59363);
double r59365 = r59364 / r59346;
double r59366 = r59349 ? r59361 : r59365;
double r59367 = r59342 ? r59347 : r59366;
return r59367;
}




Bits error versus x
Results
| Original | 30.1 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.019541465084207187Initial program 0.9
rmApplied add-log-exp0.9
rmApplied rem-log-exp0.9
if -0.019541465084207187 < x < 0.023267676544555443Initial program 60.0
Taylor expanded around 0 0.0
if 0.023267676544555443 < x Initial program 0.9
rmApplied add-exp-log0.9
rmApplied pow10.9
Applied log-pow0.9
Applied exp-prod1.0
Simplified1.0
Final simplification0.5
herbie shell --seed 2020047
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))