\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.022144219019054306:\\
\;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x}\\
\mathbf{elif}\;x \le 0.0203937394598384565:\\
\;\;\;\;\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}{\sin x}}{\frac{1}{1 - \cos x}}\\
\end{array}double f(double x) {
double r51382 = 1.0;
double r51383 = x;
double r51384 = cos(r51383);
double r51385 = r51382 - r51384;
double r51386 = sin(r51383);
double r51387 = r51385 / r51386;
return r51387;
}
double f(double x) {
double r51388 = x;
double r51389 = -0.022144219019054306;
bool r51390 = r51388 <= r51389;
double r51391 = 1.0;
double r51392 = 3.0;
double r51393 = pow(r51391, r51392);
double r51394 = cos(r51388);
double r51395 = pow(r51394, r51392);
double r51396 = r51393 - r51395;
double r51397 = r51391 * r51394;
double r51398 = fma(r51394, r51394, r51397);
double r51399 = fma(r51391, r51391, r51398);
double r51400 = sin(r51388);
double r51401 = r51399 * r51400;
double r51402 = r51396 / r51401;
double r51403 = 0.020393739459838457;
bool r51404 = r51388 <= r51403;
double r51405 = 0.041666666666666664;
double r51406 = pow(r51388, r51392);
double r51407 = 0.004166666666666667;
double r51408 = 5.0;
double r51409 = pow(r51388, r51408);
double r51410 = 0.5;
double r51411 = r51410 * r51388;
double r51412 = fma(r51407, r51409, r51411);
double r51413 = fma(r51405, r51406, r51412);
double r51414 = 1.0;
double r51415 = r51414 / r51400;
double r51416 = r51391 - r51394;
double r51417 = r51414 / r51416;
double r51418 = r51415 / r51417;
double r51419 = r51404 ? r51413 : r51418;
double r51420 = r51390 ? r51402 : r51419;
return r51420;
}




Bits error versus x
| Original | 29.6 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.022144219019054306Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
if -0.022144219019054306 < x < 0.020393739459838457Initial program 59.9
Taylor expanded around 0 0.0
Simplified0.0
if 0.020393739459838457 < x Initial program 0.9
rmApplied clear-num1.0
rmApplied div-inv1.0
Applied associate-/r*1.0
Final simplification0.5
herbie shell --seed 2020060 +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)))