\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.0196280106623787261:\\
\;\;\;\;\frac{\frac{\mathsf{log1p}\left(\mathsf{expm1}\left({1}^{3} - {\left(\cos x\right)}^{3}\right)\right)}{\mathsf{fma}\left(\cos x, \frac{{1}^{3} + {\left(\cos x\right)}^{3}}{\mathsf{fma}\left(1, 1, \cos x \cdot \left(\cos x - 1\right)\right)}, 1 \cdot 1\right)}}{\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{\frac{{1}^{3} - \sqrt[3]{{\left({\left(\cos x\right)}^{3}\right)}^{3}}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x}\\
\end{array}double f(double x) {
double r57354 = 1.0;
double r57355 = x;
double r57356 = cos(r57355);
double r57357 = r57354 - r57356;
double r57358 = sin(r57355);
double r57359 = r57357 / r57358;
return r57359;
}
double f(double x) {
double r57360 = 1.0;
double r57361 = x;
double r57362 = cos(r57361);
double r57363 = r57360 - r57362;
double r57364 = sin(r57361);
double r57365 = r57363 / r57364;
double r57366 = -0.019628010662378726;
bool r57367 = r57365 <= r57366;
double r57368 = 3.0;
double r57369 = pow(r57360, r57368);
double r57370 = pow(r57362, r57368);
double r57371 = r57369 - r57370;
double r57372 = expm1(r57371);
double r57373 = log1p(r57372);
double r57374 = r57369 + r57370;
double r57375 = r57362 - r57360;
double r57376 = r57362 * r57375;
double r57377 = fma(r57360, r57360, r57376);
double r57378 = r57374 / r57377;
double r57379 = r57360 * r57360;
double r57380 = fma(r57362, r57378, r57379);
double r57381 = r57373 / r57380;
double r57382 = r57381 / r57364;
double r57383 = -0.0;
bool r57384 = r57365 <= r57383;
double r57385 = 0.041666666666666664;
double r57386 = pow(r57361, r57368);
double r57387 = 0.004166666666666667;
double r57388 = 5.0;
double r57389 = pow(r57361, r57388);
double r57390 = 0.5;
double r57391 = r57390 * r57361;
double r57392 = fma(r57387, r57389, r57391);
double r57393 = fma(r57385, r57386, r57392);
double r57394 = pow(r57370, r57368);
double r57395 = cbrt(r57394);
double r57396 = r57369 - r57395;
double r57397 = r57360 + r57362;
double r57398 = fma(r57362, r57397, r57379);
double r57399 = r57396 / r57398;
double r57400 = r57399 / r57364;
double r57401 = r57384 ? r57393 : r57400;
double r57402 = r57367 ? r57382 : r57401;
return r57402;
}




Bits error versus x
| Original | 30.0 |
|---|---|
| Target | 0.0 |
| Herbie | 0.8 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.019628010662378726Initial program 0.8
rmApplied flip3--0.9
Simplified0.9
rmApplied log1p-expm1-u0.9
rmApplied flip3-+0.9
Simplified0.9
if -0.019628010662378726 < (/ (- 1.0 (cos x)) (sin x)) < -0.0Initial program 59.9
Taylor expanded around 0 0.4
Simplified0.4
if -0.0 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.4
rmApplied flip3--1.5
Simplified1.5
rmApplied add-cbrt-cube1.5
Simplified1.6
Final simplification0.8
herbie shell --seed 2020024 +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)))