\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.020168669770568547:\\
\;\;\;\;\frac{\sin x \cdot \left(1 - \cos x\right)}{\sin x \cdot \sin x}\\
\mathbf{elif}\;x \le 0.0257297152168081099:\\
\;\;\;\;0.041666666666666671 \cdot {x}^{3} + \left(0.00416666666666666661 \cdot {x}^{5} + 0.5 \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin x} - \frac{\cos x}{\sin x}\\
\end{array}double f(double x) {
double r89129 = 1.0;
double r89130 = x;
double r89131 = cos(r89130);
double r89132 = r89129 - r89131;
double r89133 = sin(r89130);
double r89134 = r89132 / r89133;
return r89134;
}
double f(double x) {
double r89135 = x;
double r89136 = -0.020168669770568547;
bool r89137 = r89135 <= r89136;
double r89138 = sin(r89135);
double r89139 = 1.0;
double r89140 = cos(r89135);
double r89141 = r89139 - r89140;
double r89142 = r89138 * r89141;
double r89143 = r89138 * r89138;
double r89144 = r89142 / r89143;
double r89145 = 0.02572971521680811;
bool r89146 = r89135 <= r89145;
double r89147 = 0.04166666666666667;
double r89148 = 3.0;
double r89149 = pow(r89135, r89148);
double r89150 = r89147 * r89149;
double r89151 = 0.004166666666666667;
double r89152 = 5.0;
double r89153 = pow(r89135, r89152);
double r89154 = r89151 * r89153;
double r89155 = 0.5;
double r89156 = r89155 * r89135;
double r89157 = r89154 + r89156;
double r89158 = r89150 + r89157;
double r89159 = r89139 / r89138;
double r89160 = r89140 / r89138;
double r89161 = r89159 - r89160;
double r89162 = r89146 ? r89158 : r89161;
double r89163 = r89137 ? r89144 : r89162;
return r89163;
}




Bits error versus x
Results
| Original | 30.1 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.020168669770568547Initial program 0.9
rmApplied div-sub1.1
rmApplied frac-sub1.0
Simplified1.0
if -0.020168669770568547 < x < 0.02572971521680811Initial program 59.8
rmApplied div-sub59.8
Taylor expanded around 0 0.0
if 0.02572971521680811 < x Initial program 0.9
rmApplied div-sub1.1
Final simplification0.5
herbie shell --seed 2020045
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))