\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 r61245 = 1.0;
double r61246 = x;
double r61247 = cos(r61246);
double r61248 = r61245 - r61247;
double r61249 = sin(r61246);
double r61250 = r61248 / r61249;
return r61250;
}
double f(double x) {
double r61251 = x;
double r61252 = -0.020168669770568547;
bool r61253 = r61251 <= r61252;
double r61254 = 1.0;
double r61255 = 3.0;
double r61256 = pow(r61254, r61255);
double r61257 = cos(r61251);
double r61258 = pow(r61257, r61255);
double r61259 = expm1(r61258);
double r61260 = log1p(r61259);
double r61261 = r61256 - r61260;
double r61262 = sin(r61251);
double r61263 = r61254 + r61257;
double r61264 = r61257 * r61263;
double r61265 = fma(r61254, r61254, r61264);
double r61266 = r61262 * r61265;
double r61267 = r61261 / r61266;
double r61268 = 0.02572971521680811;
bool r61269 = r61251 <= r61268;
double r61270 = 0.04166666666666663;
double r61271 = pow(r61251, r61255);
double r61272 = 0.004166666666666624;
double r61273 = 5.0;
double r61274 = pow(r61251, r61273);
double r61275 = 0.5;
double r61276 = r61275 * r61251;
double r61277 = fma(r61272, r61274, r61276);
double r61278 = fma(r61270, r61271, r61277);
double r61279 = r61254 / r61262;
double r61280 = r61257 / r61262;
double r61281 = r61279 - r61280;
double r61282 = r61269 ? r61278 : r61281;
double r61283 = r61253 ? r61267 : r61282;
return r61283;
}




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)))