\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.0198749278940998884 \lor \neg \left(x \le 0.022259987926796919\right):\\
\;\;\;\;1 \cdot \frac{1 - \cos x}{\sin x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.04166666666666663, {x}^{3}, \mathsf{fma}\left(0.004166666666666624, {x}^{5}, 0.5 \cdot x\right)\right)\\
\end{array}double f(double x) {
double r81491 = 1.0;
double r81492 = x;
double r81493 = cos(r81492);
double r81494 = r81491 - r81493;
double r81495 = sin(r81492);
double r81496 = r81494 / r81495;
return r81496;
}
double f(double x) {
double r81497 = x;
double r81498 = -0.01987492789409989;
bool r81499 = r81497 <= r81498;
double r81500 = 0.02225998792679692;
bool r81501 = r81497 <= r81500;
double r81502 = !r81501;
bool r81503 = r81499 || r81502;
double r81504 = 1.0;
double r81505 = 1.0;
double r81506 = cos(r81497);
double r81507 = r81505 - r81506;
double r81508 = sin(r81497);
double r81509 = r81507 / r81508;
double r81510 = r81504 * r81509;
double r81511 = 0.04166666666666663;
double r81512 = 3.0;
double r81513 = pow(r81497, r81512);
double r81514 = 0.004166666666666624;
double r81515 = 5.0;
double r81516 = pow(r81497, r81515);
double r81517 = 0.5;
double r81518 = r81517 * r81497;
double r81519 = fma(r81514, r81516, r81518);
double r81520 = fma(r81511, r81513, r81519);
double r81521 = r81503 ? r81510 : r81520;
return r81521;
}




Bits error versus x
| Original | 30.4 |
|---|---|
| Target | 0.0 |
| Herbie | 0.4 |
if x < -0.01987492789409989 or 0.02225998792679692 < x Initial program 0.8
rmApplied flip3--0.9
Applied associate-/l/1.0
Simplified1.0
rmApplied difference-cubes1.0
Applied times-frac0.9
Simplified0.8
if -0.01987492789409989 < x < 0.02225998792679692Initial program 59.8
rmApplied flip3--59.9
Applied associate-/l/59.9
Simplified59.9
Taylor expanded around 0 0.0
Simplified0.0
Final simplification0.4
herbie shell --seed 2020083 +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)))