\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.02120801236249347798690223498851992189884 \lor \neg \left(x \le 0.02196010544527774235867845220582239562646\right):\\
\;\;\;\;\frac{\frac{\left(1 - \cos x\right) \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \left(1 + \cos x\right)\right)}{\mathsf{fma}\left(1, 1, \cos x \cdot \left(1 + \cos x\right)\right)}}{\sin x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{24}, {x}^{3}, \mathsf{fma}\left(\frac{1}{240}, {x}^{5}, \frac{1}{2} \cdot x\right)\right)\\
\end{array}double f(double x) {
double r37381 = 1.0;
double r37382 = x;
double r37383 = cos(r37382);
double r37384 = r37381 - r37383;
double r37385 = sin(r37382);
double r37386 = r37384 / r37385;
return r37386;
}
double f(double x) {
double r37387 = x;
double r37388 = -0.021208012362493478;
bool r37389 = r37387 <= r37388;
double r37390 = 0.021960105445277742;
bool r37391 = r37387 <= r37390;
double r37392 = !r37391;
bool r37393 = r37389 || r37392;
double r37394 = 1.0;
double r37395 = cos(r37387);
double r37396 = r37394 - r37395;
double r37397 = r37394 + r37395;
double r37398 = r37395 * r37397;
double r37399 = fma(r37394, r37394, r37398);
double r37400 = r37396 * r37399;
double r37401 = r37400 / r37399;
double r37402 = sin(r37387);
double r37403 = r37401 / r37402;
double r37404 = 0.041666666666666664;
double r37405 = 3.0;
double r37406 = pow(r37387, r37405);
double r37407 = 0.004166666666666667;
double r37408 = 5.0;
double r37409 = pow(r37387, r37408);
double r37410 = 0.5;
double r37411 = r37410 * r37387;
double r37412 = fma(r37407, r37409, r37411);
double r37413 = fma(r37404, r37406, r37412);
double r37414 = r37393 ? r37403 : r37413;
return r37414;
}




Bits error versus x
| Original | 30.5 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.021208012362493478 or 0.021960105445277742 < x Initial program 0.9
rmApplied flip3--1.0
Simplified1.0
rmApplied *-un-lft-identity1.0
Applied difference-cubes1.0
Applied times-frac1.0
Simplified1.0
rmApplied associate-*r/1.0
Simplified0.9
if -0.021208012362493478 < x < 0.021960105445277742Initial program 59.9
Taylor expanded around 0 0.0
Simplified0.0
Final simplification0.5
herbie shell --seed 2019306 +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)))