\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.02184956452552735267635952709497360046953:\\
\;\;\;\;\frac{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \left(1 - \cos x\right)}{\sin x \cdot \left(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right)}\\
\mathbf{elif}\;x \le 0.02174222265971261988659612995888892328367:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{{1}^{3} - \cos x \cdot {\left(\cos x\right)}^{2}}{\sin x \cdot \left(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right)}\\
\end{array}double f(double x) {
double r54185 = 1.0;
double r54186 = x;
double r54187 = cos(r54186);
double r54188 = r54185 - r54187;
double r54189 = sin(r54186);
double r54190 = r54188 / r54189;
return r54190;
}
double f(double x) {
double r54191 = x;
double r54192 = -0.021849564525527353;
bool r54193 = r54191 <= r54192;
double r54194 = cos(r54191);
double r54195 = 1.0;
double r54196 = r54194 + r54195;
double r54197 = r54194 * r54196;
double r54198 = r54195 * r54195;
double r54199 = r54197 + r54198;
double r54200 = r54195 - r54194;
double r54201 = r54199 * r54200;
double r54202 = sin(r54191);
double r54203 = r54195 + r54194;
double r54204 = r54194 * r54203;
double r54205 = r54204 + r54198;
double r54206 = r54202 * r54205;
double r54207 = r54201 / r54206;
double r54208 = 0.02174222265971262;
bool r54209 = r54191 <= r54208;
double r54210 = 0.041666666666666664;
double r54211 = 3.0;
double r54212 = pow(r54191, r54211);
double r54213 = r54210 * r54212;
double r54214 = 0.004166666666666667;
double r54215 = 5.0;
double r54216 = pow(r54191, r54215);
double r54217 = r54214 * r54216;
double r54218 = 0.5;
double r54219 = r54218 * r54191;
double r54220 = r54217 + r54219;
double r54221 = r54213 + r54220;
double r54222 = pow(r54195, r54211);
double r54223 = 2.0;
double r54224 = pow(r54194, r54223);
double r54225 = r54194 * r54224;
double r54226 = r54222 - r54225;
double r54227 = r54226 / r54206;
double r54228 = r54209 ? r54221 : r54227;
double r54229 = r54193 ? r54207 : r54228;
return r54229;
}




Bits error versus x
Results
| Original | 29.9 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.021849564525527353Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.1
Simplified1.1
rmApplied difference-cubes1.1
Simplified1.0
if -0.021849564525527353 < x < 0.02174222265971262Initial program 59.9
Taylor expanded around 0 0.0
if 0.02174222265971262 < x Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
rmApplied cube-mult1.0
Simplified1.0
Final simplification0.5
herbie shell --seed 2019209
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))