\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.014503396267940102:\\
\;\;\;\;\frac{\frac{1}{\sin x} \cdot \frac{1}{\sin x} - \frac{\cos x}{\sin x} \cdot \frac{\cos x}{\sin x}}{\frac{1}{\sin x} + \frac{\cos x}{\sin x}} \cdot 1\\
\mathbf{elif}\;x \le 0.0228016167359906367:\\
\;\;\;\;\left(\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\right) \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\frac{\sin x + \left(-1\right) \cdot \frac{\sin x}{\cos x}}{\left(-\sin x\right) \cdot \frac{\sin x}{\cos x}} \cdot 1\\
\end{array}double code(double x) {
return ((double) (((double) (1.0 - ((double) cos(x)))) / ((double) sin(x))));
}
double code(double x) {
double VAR;
if ((x <= -0.014503396267940102)) {
VAR = ((double) (((double) (((double) (((double) (((double) (1.0 / ((double) sin(x)))) * ((double) (1.0 / ((double) sin(x)))))) - ((double) (((double) (((double) cos(x)) / ((double) sin(x)))) * ((double) (((double) cos(x)) / ((double) sin(x)))))))) / ((double) (((double) (1.0 / ((double) sin(x)))) + ((double) (((double) cos(x)) / ((double) sin(x)))))))) * 1.0));
} else {
double VAR_1;
if ((x <= 0.022801616735990637)) {
VAR_1 = ((double) (((double) (((double) (0.041666666666666664 * ((double) pow(x, 3.0)))) + ((double) (((double) (0.004166666666666667 * ((double) pow(x, 5.0)))) + ((double) (0.5 * x)))))) * 1.0));
} else {
VAR_1 = ((double) (((double) (((double) (((double) sin(x)) + ((double) (((double) -(1.0)) * ((double) (((double) sin(x)) / ((double) cos(x)))))))) / ((double) (((double) -(((double) sin(x)))) * ((double) (((double) sin(x)) / ((double) cos(x)))))))) * 1.0));
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus x
Results
| Original | 31.0 |
|---|---|
| Target | 0.0 |
| Herbie | 0.7 |
if x < -0.014503396267940102Initial program 0.9
rmApplied add-log-exp1.1
rmApplied *-un-lft-identity1.1
Applied *-un-lft-identity1.1
Applied times-frac1.1
Applied exp-prod1.2
Applied log-pow0.9
Simplified0.9
rmApplied div-sub1.2
rmApplied flip--1.6
if -0.014503396267940102 < x < 0.022801616735990637Initial program 59.9
rmApplied add-log-exp59.9
rmApplied *-un-lft-identity59.9
Applied *-un-lft-identity59.9
Applied times-frac59.9
Applied exp-prod59.9
Applied log-pow59.9
Simplified59.9
Taylor expanded around 0 0.0
if 0.022801616735990637 < x Initial program 0.9
rmApplied add-log-exp1.0
rmApplied *-un-lft-identity1.0
Applied *-un-lft-identity1.0
Applied times-frac1.0
Applied exp-prod1.1
Applied log-pow0.9
Simplified0.9
rmApplied div-sub1.1
rmApplied clear-num1.2
Applied frac-2neg1.2
Applied frac-sub1.1
Simplified1.1
Final simplification0.7
herbie shell --seed 2020113
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))