\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.02304827811785196967075961538284900598228:\\
\;\;\;\;\frac{{1}^{3} - \mathsf{expm1}\left(\mathsf{log1p}\left({\left(\cos x\right)}^{3}\right)\right)}{\sin x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \left(1 + \cos x\right)\right)}\\
\mathbf{elif}\;x \le 0.02138881640774994291609445440371928270906:\\
\;\;\;\;\mathsf{fma}\left(0.04166666666666662965923251249478198587894, {x}^{3}, \mathsf{fma}\left(0.004166666666666624108117389368999283760786, {x}^{5}, 0.5 \cdot x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{2} \cdot \cos x}{\sin x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \frac{{1}^{3} + {\left(\cos x\right)}^{3}}{\mathsf{fma}\left(1, 1, \cos x \cdot \left(\cos x - 1\right)\right)}\right)}\\
\end{array}double f(double x) {
double r66584 = 1.0;
double r66585 = x;
double r66586 = cos(r66585);
double r66587 = r66584 - r66586;
double r66588 = sin(r66585);
double r66589 = r66587 / r66588;
return r66589;
}
double f(double x) {
double r66590 = x;
double r66591 = -0.02304827811785197;
bool r66592 = r66590 <= r66591;
double r66593 = 1.0;
double r66594 = 3.0;
double r66595 = pow(r66593, r66594);
double r66596 = cos(r66590);
double r66597 = pow(r66596, r66594);
double r66598 = log1p(r66597);
double r66599 = expm1(r66598);
double r66600 = r66595 - r66599;
double r66601 = sin(r66590);
double r66602 = r66593 + r66596;
double r66603 = r66596 * r66602;
double r66604 = fma(r66593, r66593, r66603);
double r66605 = r66601 * r66604;
double r66606 = r66600 / r66605;
double r66607 = 0.021388816407749943;
bool r66608 = r66590 <= r66607;
double r66609 = 0.04166666666666663;
double r66610 = pow(r66590, r66594);
double r66611 = 0.004166666666666624;
double r66612 = 5.0;
double r66613 = pow(r66590, r66612);
double r66614 = 0.5;
double r66615 = r66614 * r66590;
double r66616 = fma(r66611, r66613, r66615);
double r66617 = fma(r66609, r66610, r66616);
double r66618 = 2.0;
double r66619 = pow(r66596, r66618);
double r66620 = r66619 * r66596;
double r66621 = r66595 - r66620;
double r66622 = r66595 + r66597;
double r66623 = r66596 - r66593;
double r66624 = r66596 * r66623;
double r66625 = fma(r66593, r66593, r66624);
double r66626 = r66622 / r66625;
double r66627 = r66596 * r66626;
double r66628 = fma(r66593, r66593, r66627);
double r66629 = r66601 * r66628;
double r66630 = r66621 / r66629;
double r66631 = r66608 ? r66617 : r66630;
double r66632 = r66592 ? r66606 : r66631;
return r66632;
}




Bits error versus x
| Original | 29.9 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.02304827811785197Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
rmApplied expm1-log1p-u1.1
if -0.02304827811785197 < x < 0.021388816407749943Initial program 59.9
rmApplied flip3--59.9
Applied associate-/l/59.9
Simplified59.9
rmApplied add-cube-cbrt60.0
Applied unpow-prod-down60.0
Simplified59.9
Simplified59.9
Taylor expanded around 0 0.0
Simplified0.0
if 0.021388816407749943 < x Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
rmApplied add-cube-cbrt1.8
Applied unpow-prod-down1.8
Simplified1.3
Simplified1.0
rmApplied flip3-+1.0
Simplified1.0
Final simplification0.5
herbie shell --seed 2019325 +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)))