\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.001308568773005096318520767972870544326724:\\
\;\;\;\;\log \left(e^{\frac{1 - \cos x}{\sin x}}\right)\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 4.957178312169810962668929968898134941213 \cdot 10^{-8}:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - \cos x}{\sqrt{\sin x}} \cdot \frac{1}{\sqrt{\sin x}}\\
\end{array}double f(double x) {
double r40246 = 1.0;
double r40247 = x;
double r40248 = cos(r40247);
double r40249 = r40246 - r40248;
double r40250 = sin(r40247);
double r40251 = r40249 / r40250;
return r40251;
}
double f(double x) {
double r40252 = 1.0;
double r40253 = x;
double r40254 = cos(r40253);
double r40255 = r40252 - r40254;
double r40256 = sin(r40253);
double r40257 = r40255 / r40256;
double r40258 = -0.0013085687730050963;
bool r40259 = r40257 <= r40258;
double r40260 = exp(r40257);
double r40261 = log(r40260);
double r40262 = 4.957178312169811e-08;
bool r40263 = r40257 <= r40262;
double r40264 = 0.041666666666666664;
double r40265 = 3.0;
double r40266 = pow(r40253, r40265);
double r40267 = r40264 * r40266;
double r40268 = 0.004166666666666667;
double r40269 = 5.0;
double r40270 = pow(r40253, r40269);
double r40271 = r40268 * r40270;
double r40272 = 0.5;
double r40273 = r40272 * r40253;
double r40274 = r40271 + r40273;
double r40275 = r40267 + r40274;
double r40276 = sqrt(r40256);
double r40277 = r40255 / r40276;
double r40278 = 1.0;
double r40279 = r40278 / r40276;
double r40280 = r40277 * r40279;
double r40281 = r40263 ? r40275 : r40280;
double r40282 = r40259 ? r40261 : r40281;
return r40282;
}




Bits error versus x
Results
| Original | 30.4 |
|---|---|
| Target | 0.0 |
| Herbie | 0.6 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.0013085687730050963Initial program 0.9
rmApplied add-log-exp1.1
if -0.0013085687730050963 < (/ (- 1.0 (cos x)) (sin x)) < 4.957178312169811e-08Initial program 60.2
Taylor expanded around 0 0.0
if 4.957178312169811e-08 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.3
rmApplied add-log-exp1.4
rmApplied add-sqr-sqrt1.5
Applied *-un-lft-identity1.5
Applied times-frac1.6
Applied exp-prod1.7
Applied log-pow1.5
Simplified1.5
Final simplification0.6
herbie shell --seed 2019347
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))