\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.0227880187083014697224658817731324234046 \lor \neg \left(x \le 0.02338074252416355927608471176881721476093\right):\\
\;\;\;\;\frac{e^{\log \left(1 - \cos x\right)}}{\sin x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.04166666666666662965923251249478198587894, {x}^{3}, \mathsf{fma}\left(0.004166666666666624108117389368999283760786, {x}^{5}, 0.5 \cdot x\right)\right)\\
\end{array}double f(double x) {
double r50382 = 1.0;
double r50383 = x;
double r50384 = cos(r50383);
double r50385 = r50382 - r50384;
double r50386 = sin(r50383);
double r50387 = r50385 / r50386;
return r50387;
}
double f(double x) {
double r50388 = x;
double r50389 = -0.02278801870830147;
bool r50390 = r50388 <= r50389;
double r50391 = 0.02338074252416356;
bool r50392 = r50388 <= r50391;
double r50393 = !r50392;
bool r50394 = r50390 || r50393;
double r50395 = 1.0;
double r50396 = cos(r50388);
double r50397 = r50395 - r50396;
double r50398 = log(r50397);
double r50399 = exp(r50398);
double r50400 = sin(r50388);
double r50401 = r50399 / r50400;
double r50402 = 0.04166666666666663;
double r50403 = 3.0;
double r50404 = pow(r50388, r50403);
double r50405 = 0.004166666666666624;
double r50406 = 5.0;
double r50407 = pow(r50388, r50406);
double r50408 = 0.5;
double r50409 = r50408 * r50388;
double r50410 = fma(r50405, r50407, r50409);
double r50411 = fma(r50402, r50404, r50410);
double r50412 = r50394 ? r50401 : r50411;
return r50412;
}




Bits error versus x
| Original | 30.4 |
|---|---|
| Target | 0 |
| Herbie | 0.5 |
if x < -0.02278801870830147 or 0.02338074252416356 < x Initial program 0.9
rmApplied add-log-exp1.1
Applied add-log-exp1.1
Applied diff-log1.3
Simplified1.1
rmApplied add-exp-log1.1
Simplified0.9
if -0.02278801870830147 < x < 0.02338074252416356Initial program 59.8
rmApplied add-log-exp59.8
rmApplied flip3--59.8
Simplified59.8
Taylor expanded around 0 0.0
Simplified0.0
Final simplification0.5
herbie shell --seed 2019351 +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)))