\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.02184956452552735267635952709497360046953:\\
\;\;\;\;\frac{\mathsf{fma}\left(1, 1, \cos x \cdot \left(\cos x + 1\right)\right) \cdot \left(1 - \cos x\right)}{\sin x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \left(\cos x + 1\right)\right)}\\
\mathbf{elif}\;x \le 0.02174222265971261988659612995888892328367:\\
\;\;\;\;\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{{1}^{3} - \left(\cos x \cdot \cos x\right) \cdot \cos x}{\sin x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \left(\cos x + 1\right)\right)}\\
\end{array}double f(double x) {
double r74327 = 1.0;
double r74328 = x;
double r74329 = cos(r74328);
double r74330 = r74327 - r74329;
double r74331 = sin(r74328);
double r74332 = r74330 / r74331;
return r74332;
}
double f(double x) {
double r74333 = x;
double r74334 = -0.021849564525527353;
bool r74335 = r74333 <= r74334;
double r74336 = 1.0;
double r74337 = cos(r74333);
double r74338 = r74337 + r74336;
double r74339 = r74337 * r74338;
double r74340 = fma(r74336, r74336, r74339);
double r74341 = r74336 - r74337;
double r74342 = r74340 * r74341;
double r74343 = sin(r74333);
double r74344 = r74343 * r74340;
double r74345 = r74342 / r74344;
double r74346 = 0.02174222265971262;
bool r74347 = r74333 <= r74346;
double r74348 = 0.041666666666666664;
double r74349 = 3.0;
double r74350 = pow(r74333, r74349);
double r74351 = 0.004166666666666667;
double r74352 = 5.0;
double r74353 = pow(r74333, r74352);
double r74354 = 0.5;
double r74355 = r74354 * r74333;
double r74356 = fma(r74351, r74353, r74355);
double r74357 = fma(r74348, r74350, r74356);
double r74358 = pow(r74336, r74349);
double r74359 = r74337 * r74337;
double r74360 = r74359 * r74337;
double r74361 = r74358 - r74360;
double r74362 = r74361 / r74344;
double r74363 = r74347 ? r74357 : r74362;
double r74364 = r74335 ? r74345 : r74363;
return r74364;
}




Bits error versus x
| 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
Simplified0.0
if 0.02174222265971262 < x Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
rmApplied add-cbrt-cube1.4
Applied rem-cube-cbrt1.0
Final simplification0.5
herbie shell --seed 2019209 +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)))