\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.02408789324737697218337117988085083197802:\\
\;\;\;\;\frac{1}{\frac{\sin x}{\mathsf{expm1}\left(\mathsf{log1p}\left(1 - \cos x\right)\right)}}\\
\mathbf{elif}\;x \le 0.02070648332399807264869728840039897477254:\\
\;\;\;\;\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{{1}^{3} - \sqrt[3]{{\left({\left(\cos x\right)}^{3}\right)}^{3}}}{\sin x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \left(1 + \cos x\right)\right)}\\
\end{array}double f(double x) {
double r60497 = 1.0;
double r60498 = x;
double r60499 = cos(r60498);
double r60500 = r60497 - r60499;
double r60501 = sin(r60498);
double r60502 = r60500 / r60501;
return r60502;
}
double f(double x) {
double r60503 = x;
double r60504 = -0.024087893247376972;
bool r60505 = r60503 <= r60504;
double r60506 = 1.0;
double r60507 = sin(r60503);
double r60508 = 1.0;
double r60509 = cos(r60503);
double r60510 = r60508 - r60509;
double r60511 = log1p(r60510);
double r60512 = expm1(r60511);
double r60513 = r60507 / r60512;
double r60514 = r60506 / r60513;
double r60515 = 0.020706483323998073;
bool r60516 = r60503 <= r60515;
double r60517 = 0.041666666666666664;
double r60518 = 3.0;
double r60519 = pow(r60503, r60518);
double r60520 = 0.004166666666666667;
double r60521 = 5.0;
double r60522 = pow(r60503, r60521);
double r60523 = 0.5;
double r60524 = r60523 * r60503;
double r60525 = fma(r60520, r60522, r60524);
double r60526 = fma(r60517, r60519, r60525);
double r60527 = pow(r60508, r60518);
double r60528 = pow(r60509, r60518);
double r60529 = pow(r60528, r60518);
double r60530 = cbrt(r60529);
double r60531 = r60527 - r60530;
double r60532 = r60508 + r60509;
double r60533 = r60509 * r60532;
double r60534 = fma(r60508, r60508, r60533);
double r60535 = r60507 * r60534;
double r60536 = r60531 / r60535;
double r60537 = r60516 ? r60526 : r60536;
double r60538 = r60505 ? r60514 : r60537;
return r60538;
}




Bits error versus x
| Original | 29.9 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.024087893247376972Initial program 0.9
rmApplied clear-num1.0
rmApplied expm1-log1p-u1.1
if -0.024087893247376972 < x < 0.020706483323998073Initial program 59.8
Taylor expanded around 0 0.0
Simplified0.0
if 0.020706483323998073 < x Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
rmApplied add-cbrt-cube1.1
Simplified1.1
Final simplification0.5
herbie shell --seed 2019323 +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)))