\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.02294790868899147795456627818566630594432:\\
\;\;\;\;\log \left(e^{\frac{1 - \cos x}{\sin x}}\right)\\
\mathbf{elif}\;x \le 0.02393964535351434871901510348379815695807:\\
\;\;\;\;\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{{1}^{3} - {\left(\cos x\right)}^{3}}{\sin x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \frac{{\left(\cos x\right)}^{2} - 1 \cdot 1}{\cos x - 1}\right)}\\
\end{array}double f(double x) {
double r57292 = 1.0;
double r57293 = x;
double r57294 = cos(r57293);
double r57295 = r57292 - r57294;
double r57296 = sin(r57293);
double r57297 = r57295 / r57296;
return r57297;
}
double f(double x) {
double r57298 = x;
double r57299 = -0.022947908688991478;
bool r57300 = r57298 <= r57299;
double r57301 = 1.0;
double r57302 = cos(r57298);
double r57303 = r57301 - r57302;
double r57304 = sin(r57298);
double r57305 = r57303 / r57304;
double r57306 = exp(r57305);
double r57307 = log(r57306);
double r57308 = 0.02393964535351435;
bool r57309 = r57298 <= r57308;
double r57310 = 0.041666666666666664;
double r57311 = 3.0;
double r57312 = pow(r57298, r57311);
double r57313 = 0.004166666666666667;
double r57314 = 5.0;
double r57315 = pow(r57298, r57314);
double r57316 = 0.5;
double r57317 = r57316 * r57298;
double r57318 = fma(r57313, r57315, r57317);
double r57319 = fma(r57310, r57312, r57318);
double r57320 = pow(r57301, r57311);
double r57321 = pow(r57302, r57311);
double r57322 = r57320 - r57321;
double r57323 = 2.0;
double r57324 = pow(r57302, r57323);
double r57325 = r57301 * r57301;
double r57326 = r57324 - r57325;
double r57327 = r57302 - r57301;
double r57328 = r57326 / r57327;
double r57329 = r57302 * r57328;
double r57330 = fma(r57301, r57301, r57329);
double r57331 = r57304 * r57330;
double r57332 = r57322 / r57331;
double r57333 = r57309 ? r57319 : r57332;
double r57334 = r57300 ? r57307 : r57333;
return r57334;
}




Bits error versus x
| Original | 30.5 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.022947908688991478Initial program 0.9
rmApplied add-log-exp1.0
if -0.022947908688991478 < x < 0.02393964535351435Initial program 59.9
Taylor expanded around 0 0.0
Simplified0.0
if 0.02393964535351435 < x Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
rmApplied flip-+1.0
Simplified1.0
Final simplification0.5
herbie shell --seed 2019235 +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)))