\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.004893422048095925:\\
\;\;\;\;\log \left(\mathsf{expm1}\left(\mathsf{log1p}\left(e^{\frac{1 - \cos x}{\sin x}}\right)\right)\right)\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 2.98402005876572314 \cdot 10^{-5}:\\
\;\;\;\;\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}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1 - \cos x}{\sin x}\right)\right)\\
\end{array}double f(double x) {
double r51307 = 1.0;
double r51308 = x;
double r51309 = cos(r51308);
double r51310 = r51307 - r51309;
double r51311 = sin(r51308);
double r51312 = r51310 / r51311;
return r51312;
}
double f(double x) {
double r51313 = 1.0;
double r51314 = x;
double r51315 = cos(r51314);
double r51316 = r51313 - r51315;
double r51317 = sin(r51314);
double r51318 = r51316 / r51317;
double r51319 = -0.0048934220480959245;
bool r51320 = r51318 <= r51319;
double r51321 = exp(r51318);
double r51322 = log1p(r51321);
double r51323 = expm1(r51322);
double r51324 = log(r51323);
double r51325 = 2.984020058765723e-05;
bool r51326 = r51318 <= r51325;
double r51327 = 0.041666666666666664;
double r51328 = 3.0;
double r51329 = pow(r51314, r51328);
double r51330 = 0.004166666666666667;
double r51331 = 5.0;
double r51332 = pow(r51314, r51331);
double r51333 = 0.5;
double r51334 = r51333 * r51314;
double r51335 = fma(r51330, r51332, r51334);
double r51336 = fma(r51327, r51329, r51335);
double r51337 = expm1(r51318);
double r51338 = log1p(r51337);
double r51339 = r51326 ? r51336 : r51338;
double r51340 = r51320 ? r51324 : r51339;
return r51340;
}




Bits error versus x
| Original | 30.4 |
|---|---|
| Target | 0.0 |
| Herbie | 0.6 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.0048934220480959245Initial program 0.9
rmApplied add-log-exp1.0
rmApplied expm1-log1p-u1.1
if -0.0048934220480959245 < (/ (- 1.0 (cos x)) (sin x)) < 2.984020058765723e-05Initial program 59.9
Taylor expanded around 0 0.1
Simplified0.1
if 2.984020058765723e-05 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.1
rmApplied log1p-expm1-u1.1
Final simplification0.6
herbie shell --seed 2020046 +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)))