\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.0242809220681906925976001332401210675016:\\
\;\;\;\;\frac{1}{\sin x} - \frac{\cos x}{\sin x}\\
\mathbf{elif}\;x \le 0.02108811747029423755428467757155885919929:\\
\;\;\;\;\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{\sin x \cdot \left(1 - \cos x\right)}{\sin x \cdot \sin x}\\
\end{array}double f(double x) {
double r58173 = 1.0;
double r58174 = x;
double r58175 = cos(r58174);
double r58176 = r58173 - r58175;
double r58177 = sin(r58174);
double r58178 = r58176 / r58177;
return r58178;
}
double f(double x) {
double r58179 = x;
double r58180 = -0.024280922068190693;
bool r58181 = r58179 <= r58180;
double r58182 = 1.0;
double r58183 = sin(r58179);
double r58184 = r58182 / r58183;
double r58185 = cos(r58179);
double r58186 = r58185 / r58183;
double r58187 = r58184 - r58186;
double r58188 = 0.021088117470294238;
bool r58189 = r58179 <= r58188;
double r58190 = 0.041666666666666664;
double r58191 = 3.0;
double r58192 = pow(r58179, r58191);
double r58193 = 0.004166666666666667;
double r58194 = 5.0;
double r58195 = pow(r58179, r58194);
double r58196 = 0.5;
double r58197 = r58196 * r58179;
double r58198 = fma(r58193, r58195, r58197);
double r58199 = fma(r58190, r58192, r58198);
double r58200 = r58182 - r58185;
double r58201 = r58183 * r58200;
double r58202 = r58183 * r58183;
double r58203 = r58201 / r58202;
double r58204 = r58189 ? r58199 : r58203;
double r58205 = r58181 ? r58187 : r58204;
return r58205;
}




Bits error versus x
| Original | 30.2 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.024280922068190693Initial program 0.9
rmApplied div-sub1.1
if -0.024280922068190693 < x < 0.021088117470294238Initial program 60.0
Taylor expanded around 0 0.0
Simplified0.0
if 0.021088117470294238 < x Initial program 0.9
rmApplied div-sub1.1
rmApplied frac-sub1.1
Simplified1.0
Final simplification0.5
herbie shell --seed 2020001 +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)))