\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.0242859294884205483:\\
\;\;\;\;\frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\sin x}}{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}\\
\mathbf{elif}\;x \le 0.0212898443058771626:\\
\;\;\;\;\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{e^{\log \left(\sqrt{1 - \cos x}\right)}}{\frac{\sin x}{\sqrt{1 - \cos x}}}\\
\end{array}double f(double x) {
double r73138 = 1.0;
double r73139 = x;
double r73140 = cos(r73139);
double r73141 = r73138 - r73140;
double r73142 = sin(r73139);
double r73143 = r73141 / r73142;
return r73143;
}
double f(double x) {
double r73144 = x;
double r73145 = -0.02428592948842055;
bool r73146 = r73144 <= r73145;
double r73147 = 1.0;
double r73148 = 3.0;
double r73149 = pow(r73147, r73148);
double r73150 = cos(r73144);
double r73151 = pow(r73150, r73148);
double r73152 = r73149 - r73151;
double r73153 = sin(r73144);
double r73154 = r73152 / r73153;
double r73155 = r73147 * r73147;
double r73156 = r73150 * r73150;
double r73157 = r73147 * r73150;
double r73158 = r73156 + r73157;
double r73159 = r73155 + r73158;
double r73160 = r73154 / r73159;
double r73161 = 0.021289844305877163;
bool r73162 = r73144 <= r73161;
double r73163 = 0.041666666666666664;
double r73164 = pow(r73144, r73148);
double r73165 = 0.004166666666666667;
double r73166 = 5.0;
double r73167 = pow(r73144, r73166);
double r73168 = 0.5;
double r73169 = r73168 * r73144;
double r73170 = fma(r73165, r73167, r73169);
double r73171 = fma(r73163, r73164, r73170);
double r73172 = r73147 - r73150;
double r73173 = sqrt(r73172);
double r73174 = log(r73173);
double r73175 = exp(r73174);
double r73176 = r73153 / r73173;
double r73177 = r73175 / r73176;
double r73178 = r73162 ? r73171 : r73177;
double r73179 = r73146 ? r73160 : r73178;
return r73179;
}




Bits error versus x
| Original | 30.1 |
|---|---|
| Target | 0.0 |
| Herbie | 0.6 |
if x < -0.02428592948842055Initial program 0.9
rmApplied div-inv1.0
rmApplied flip3--1.1
Applied associate-*l/1.1
Simplified1.0
if -0.02428592948842055 < x < 0.021289844305877163Initial program 59.8
Taylor expanded around 0 0.0
Simplified0.0
if 0.021289844305877163 < x Initial program 0.9
rmApplied add-exp-log0.9
rmApplied add-sqr-sqrt1.2
Applied log-prod1.2
Applied exp-sum1.2
Applied associate-/l*1.2
Simplified1.2
Final simplification0.6
herbie shell --seed 2020081 +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)))