\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.02231606801598658498808624983666959451512:\\
\;\;\;\;\frac{e^{\log \left({1}^{3} - {\left(\cos x\right)}^{3}\right)}}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}\\
\mathbf{elif}\;x \le 0.02219699502236853819181483515876607270911:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;{e}^{\left(\log \left(1 - \cos x\right)\right)} \cdot \frac{1}{\sin x}\\
\end{array}double f(double x) {
double r71120 = 1.0;
double r71121 = x;
double r71122 = cos(r71121);
double r71123 = r71120 - r71122;
double r71124 = sin(r71121);
double r71125 = r71123 / r71124;
return r71125;
}
double f(double x) {
double r71126 = x;
double r71127 = -0.022316068015986585;
bool r71128 = r71126 <= r71127;
double r71129 = 1.0;
double r71130 = 3.0;
double r71131 = pow(r71129, r71130);
double r71132 = cos(r71126);
double r71133 = pow(r71132, r71130);
double r71134 = r71131 - r71133;
double r71135 = log(r71134);
double r71136 = exp(r71135);
double r71137 = r71132 + r71129;
double r71138 = r71132 * r71137;
double r71139 = r71129 * r71129;
double r71140 = r71138 + r71139;
double r71141 = sin(r71126);
double r71142 = r71140 * r71141;
double r71143 = r71136 / r71142;
double r71144 = 0.022196995022368538;
bool r71145 = r71126 <= r71144;
double r71146 = 0.041666666666666664;
double r71147 = pow(r71126, r71130);
double r71148 = r71146 * r71147;
double r71149 = 0.004166666666666667;
double r71150 = 5.0;
double r71151 = pow(r71126, r71150);
double r71152 = r71149 * r71151;
double r71153 = 0.5;
double r71154 = r71153 * r71126;
double r71155 = r71152 + r71154;
double r71156 = r71148 + r71155;
double r71157 = exp(1.0);
double r71158 = r71129 - r71132;
double r71159 = log(r71158);
double r71160 = pow(r71157, r71159);
double r71161 = 1.0;
double r71162 = r71161 / r71141;
double r71163 = r71160 * r71162;
double r71164 = r71145 ? r71156 : r71163;
double r71165 = r71128 ? r71143 : r71164;
return r71165;
}




Bits error versus x
Results
| Original | 29.9 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.022316068015986585Initial program 0.9
rmApplied add-exp-log0.9
rmApplied flip3--1.0
Applied log-div1.1
Applied exp-diff1.0
Applied associate-/l/1.0
Simplified1.0
if -0.022316068015986585 < x < 0.022196995022368538Initial program 59.9
Taylor expanded around 0 0.0
if 0.022196995022368538 < x Initial program 0.9
rmApplied add-exp-log0.9
rmApplied pow10.9
Applied log-pow0.9
Applied exp-prod1.0
Simplified1.0
rmApplied div-inv1.0
Final simplification0.5
herbie shell --seed 2019325
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))