\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.020168669770568547:\\
\;\;\;\;\frac{{1}^{3} - \mathsf{log1p}\left(\mathsf{expm1}\left({\left(\cos x\right)}^{3}\right)\right)}{\sin x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \left(1 + \cos x\right)\right)}\\
\mathbf{elif}\;x \le 0.0257297152168081099:\\
\;\;\;\;\mathsf{fma}\left(0.04166666666666663, {x}^{3}, \mathsf{fma}\left(0.004166666666666624, {x}^{5}, 0.5 \cdot x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin x} - \frac{\cos x}{\sin x}\\
\end{array}double f(double x) {
double r108662 = 1.0;
double r108663 = x;
double r108664 = cos(r108663);
double r108665 = r108662 - r108664;
double r108666 = sin(r108663);
double r108667 = r108665 / r108666;
return r108667;
}
double f(double x) {
double r108668 = x;
double r108669 = -0.020168669770568547;
bool r108670 = r108668 <= r108669;
double r108671 = 1.0;
double r108672 = 3.0;
double r108673 = pow(r108671, r108672);
double r108674 = cos(r108668);
double r108675 = pow(r108674, r108672);
double r108676 = expm1(r108675);
double r108677 = log1p(r108676);
double r108678 = r108673 - r108677;
double r108679 = sin(r108668);
double r108680 = r108671 + r108674;
double r108681 = r108674 * r108680;
double r108682 = fma(r108671, r108671, r108681);
double r108683 = r108679 * r108682;
double r108684 = r108678 / r108683;
double r108685 = 0.02572971521680811;
bool r108686 = r108668 <= r108685;
double r108687 = 0.04166666666666663;
double r108688 = pow(r108668, r108672);
double r108689 = 0.004166666666666624;
double r108690 = 5.0;
double r108691 = pow(r108668, r108690);
double r108692 = 0.5;
double r108693 = r108692 * r108668;
double r108694 = fma(r108689, r108691, r108693);
double r108695 = fma(r108687, r108688, r108694);
double r108696 = r108671 / r108679;
double r108697 = r108674 / r108679;
double r108698 = r108696 - r108697;
double r108699 = r108686 ? r108695 : r108698;
double r108700 = r108670 ? r108684 : r108699;
return r108700;
}




Bits error versus x
| Original | 30.1 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.020168669770568547Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
rmApplied log1p-expm1-u1.0
if -0.020168669770568547 < x < 0.02572971521680811Initial program 59.8
rmApplied flip3--59.8
Applied associate-/l/59.8
Simplified59.8
Taylor expanded around 0 0.0
Simplified0.0
if 0.02572971521680811 < x Initial program 0.9
rmApplied div-sub1.1
Final simplification0.5
herbie shell --seed 2020045 +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)))