\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -2.76308119989467809 \cdot 10^{-4}:\\
\;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x}\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le -0.0:\\
\;\;\;\;\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}{\sin x} - \frac{\cos x}{\sin x}\\
\end{array}double f(double x) {
double r76572 = 1.0;
double r76573 = x;
double r76574 = cos(r76573);
double r76575 = r76572 - r76574;
double r76576 = sin(r76573);
double r76577 = r76575 / r76576;
return r76577;
}
double f(double x) {
double r76578 = 1.0;
double r76579 = x;
double r76580 = cos(r76579);
double r76581 = r76578 - r76580;
double r76582 = sin(r76579);
double r76583 = r76581 / r76582;
double r76584 = -0.0002763081199894678;
bool r76585 = r76583 <= r76584;
double r76586 = 3.0;
double r76587 = pow(r76578, r76586);
double r76588 = pow(r76580, r76586);
double r76589 = r76587 - r76588;
double r76590 = r76578 * r76580;
double r76591 = fma(r76580, r76580, r76590);
double r76592 = fma(r76578, r76578, r76591);
double r76593 = r76592 * r76582;
double r76594 = r76589 / r76593;
double r76595 = -0.0;
bool r76596 = r76583 <= r76595;
double r76597 = 0.041666666666666664;
double r76598 = pow(r76579, r76586);
double r76599 = 0.004166666666666667;
double r76600 = 5.0;
double r76601 = pow(r76579, r76600);
double r76602 = 0.5;
double r76603 = r76602 * r76579;
double r76604 = fma(r76599, r76601, r76603);
double r76605 = fma(r76597, r76598, r76604);
double r76606 = r76578 / r76582;
double r76607 = r76580 / r76582;
double r76608 = r76606 - r76607;
double r76609 = r76596 ? r76605 : r76608;
double r76610 = r76585 ? r76594 : r76609;
return r76610;
}




Bits error versus x
| Original | 30.3 |
|---|---|
| Target | 0.0 |
| Herbie | 0.7 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.0002763081199894678Initial program 1.0
rmApplied add-log-exp1.2
rmApplied clear-num1.2
Taylor expanded around inf 1.0
rmApplied flip3--1.1
Applied associate-/l/1.1
Simplified1.1
if -0.0002763081199894678 < (/ (- 1.0 (cos x)) (sin x)) < -0.0Initial program 60.3
Taylor expanded around 0 0.0
Simplified0.0
if -0.0 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.3
rmApplied div-sub1.5
Final simplification0.7
herbie shell --seed 2020062 +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)))