\frac{1.0 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1.0 - \cos x}{\sin x} \le -0.008153236898019485:\\
\;\;\;\;\frac{e^{\log \left(1.0 - \cos x\right)}}{\sin x}\\
\mathbf{elif}\;\frac{1.0 - \cos x}{\sin x} \le 0.0:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{240}, {x}^{5}, x \cdot \frac{1}{2} + x \cdot \left(\left(\frac{1}{24} \cdot x\right) \cdot x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1.0 - \cos x}{\sin x}\\
\end{array}double f(double x) {
double r4173423 = 1.0;
double r4173424 = x;
double r4173425 = cos(r4173424);
double r4173426 = r4173423 - r4173425;
double r4173427 = sin(r4173424);
double r4173428 = r4173426 / r4173427;
return r4173428;
}
double f(double x) {
double r4173429 = 1.0;
double r4173430 = x;
double r4173431 = cos(r4173430);
double r4173432 = r4173429 - r4173431;
double r4173433 = sin(r4173430);
double r4173434 = r4173432 / r4173433;
double r4173435 = -0.008153236898019485;
bool r4173436 = r4173434 <= r4173435;
double r4173437 = log(r4173432);
double r4173438 = exp(r4173437);
double r4173439 = r4173438 / r4173433;
double r4173440 = 0.0;
bool r4173441 = r4173434 <= r4173440;
double r4173442 = 0.004166666666666667;
double r4173443 = 5.0;
double r4173444 = pow(r4173430, r4173443);
double r4173445 = 0.5;
double r4173446 = r4173430 * r4173445;
double r4173447 = 0.041666666666666664;
double r4173448 = r4173447 * r4173430;
double r4173449 = r4173448 * r4173430;
double r4173450 = r4173430 * r4173449;
double r4173451 = r4173446 + r4173450;
double r4173452 = fma(r4173442, r4173444, r4173451);
double r4173453 = r4173441 ? r4173452 : r4173434;
double r4173454 = r4173436 ? r4173439 : r4173453;
return r4173454;
}




Bits error versus x
| Original | 29.6 |
|---|---|
| Target | 0.0 |
| Herbie | 0.7 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.008153236898019485Initial program 0.8
rmApplied add-exp-log0.8
if -0.008153236898019485 < (/ (- 1.0 (cos x)) (sin x)) < 0.0Initial program 60.1
Taylor expanded around 0 0.1
Simplified0.1
rmApplied fma-udef0.1
Applied distribute-lft-in0.1
if 0.0 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.5
rmApplied add-log-exp1.6
rmApplied rem-log-exp1.5
Final simplification0.7
herbie shell --seed 2019165 +o rules:numerics
(FPCore (x)
:name "tanhf (example 3.4)"
:herbie-expected 2
:herbie-target
(tan (/ x 2.0))
(/ (- 1.0 (cos x)) (sin x)))