\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -7.531467756712890016922851144087758257228 \cdot 10^{-5}:\\
\;\;\;\;\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.546632212092768594597497200382463233836 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{24}, {x}^{3}, \mathsf{fma}\left({x}^{5}, \frac{1}{240}, x \cdot \frac{1}{2}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - \cos x\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{\sin x}\right)\right)\\
\end{array}double f(double x) {
double r40481 = 1.0;
double r40482 = x;
double r40483 = cos(r40482);
double r40484 = r40481 - r40483;
double r40485 = sin(r40482);
double r40486 = r40484 / r40485;
return r40486;
}
double f(double x) {
double r40487 = 1.0;
double r40488 = x;
double r40489 = cos(r40488);
double r40490 = r40487 - r40489;
double r40491 = sin(r40488);
double r40492 = r40490 / r40491;
double r40493 = -7.53146775671289e-05;
bool r40494 = r40492 <= r40493;
double r40495 = exp(r40492);
double r40496 = log1p(r40495);
double r40497 = expm1(r40496);
double r40498 = log(r40497);
double r40499 = 2.5466322120927686e-06;
bool r40500 = r40492 <= r40499;
double r40501 = 0.041666666666666664;
double r40502 = 3.0;
double r40503 = pow(r40488, r40502);
double r40504 = 5.0;
double r40505 = pow(r40488, r40504);
double r40506 = 0.004166666666666667;
double r40507 = 0.5;
double r40508 = r40488 * r40507;
double r40509 = fma(r40505, r40506, r40508);
double r40510 = fma(r40501, r40503, r40509);
double r40511 = 1.0;
double r40512 = r40511 / r40491;
double r40513 = expm1(r40512);
double r40514 = log1p(r40513);
double r40515 = r40490 * r40514;
double r40516 = r40500 ? r40510 : r40515;
double r40517 = r40494 ? r40498 : r40516;
return r40517;
}




Bits error versus x
| Original | 30.0 |
|---|---|
| Target | 0.0 |
| Herbie | 0.8 |
if (/ (- 1.0 (cos x)) (sin x)) < -7.53146775671289e-05Initial program 1.0
rmApplied add-log-exp1.1
rmApplied expm1-log1p-u1.3
if -7.53146775671289e-05 < (/ (- 1.0 (cos x)) (sin x)) < 2.5466322120927686e-06Initial program 60.3
Taylor expanded around 0 0.0
Simplified0.0
if 2.5466322120927686e-06 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.2
rmApplied add-log-exp1.3
rmApplied div-inv1.4
Applied exp-prod1.7
Applied log-pow1.5
Simplified1.3
rmApplied log1p-expm1-u1.8
Final simplification0.8
herbie shell --seed 2019196 +o rules:numerics
(FPCore (x)
:name "tanhf (example 3.4)"
:herbie-expected 2
:herbie-target
(tan (/ x 2.0))
(/ (- 1.0 (cos x)) (sin x)))