\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.020365697215685236:\\
\;\;\;\;\left(\frac{1 - \cos x}{\sin x} \cdot \left(1 + \cos x\right)\right) \cdot \frac{1}{1 + \cos x}\\
\mathbf{elif}\;x \le 0.0228384202901172999:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(1 - \cos x\right) \cdot \frac{\cos x + 1}{\sin x}\right) \cdot \frac{1}{1 + \cos x}\\
\end{array}double f(double x) {
double r41641 = 1.0;
double r41642 = x;
double r41643 = cos(r41642);
double r41644 = r41641 - r41643;
double r41645 = sin(r41642);
double r41646 = r41644 / r41645;
return r41646;
}
double f(double x) {
double r41647 = x;
double r41648 = -0.020365697215685236;
bool r41649 = r41647 <= r41648;
double r41650 = 1.0;
double r41651 = cos(r41647);
double r41652 = r41650 - r41651;
double r41653 = sin(r41647);
double r41654 = r41652 / r41653;
double r41655 = r41650 + r41651;
double r41656 = r41654 * r41655;
double r41657 = 1.0;
double r41658 = r41657 / r41655;
double r41659 = r41656 * r41658;
double r41660 = 0.0228384202901173;
bool r41661 = r41647 <= r41660;
double r41662 = 0.041666666666666664;
double r41663 = 3.0;
double r41664 = pow(r41647, r41663);
double r41665 = r41662 * r41664;
double r41666 = 0.004166666666666667;
double r41667 = 5.0;
double r41668 = pow(r41647, r41667);
double r41669 = r41666 * r41668;
double r41670 = 0.5;
double r41671 = r41670 * r41647;
double r41672 = r41669 + r41671;
double r41673 = r41665 + r41672;
double r41674 = r41651 + r41650;
double r41675 = r41674 / r41653;
double r41676 = r41652 * r41675;
double r41677 = r41676 * r41658;
double r41678 = r41661 ? r41673 : r41677;
double r41679 = r41649 ? r41659 : r41678;
return r41679;
}




Bits error versus x
Results
| Original | 30.4 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.020365697215685236Initial program 1.0
rmApplied clear-num1.0
rmApplied flip--1.4
Applied associate-/r/1.4
Applied add-cube-cbrt1.4
Applied times-frac1.5
Simplified1.1
Simplified1.1
if -0.020365697215685236 < x < 0.0228384202901173Initial program 59.7
Taylor expanded around 0 0.0
if 0.0228384202901173 < x Initial program 0.8
rmApplied clear-num0.9
rmApplied flip--1.4
Applied associate-/r/1.4
Applied add-cube-cbrt1.4
Applied times-frac1.4
Simplified0.9
Simplified0.9
rmApplied div-inv1.0
Applied associate-*l*1.0
Simplified1.0
Final simplification0.5
herbie shell --seed 2020046
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))