\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.02373580573239164950849477975225454429165:\\
\;\;\;\;\frac{\mathsf{log1p}\left(\log \left(e^{\mathsf{expm1}\left({1}^{3} - {\left(\cos x\right)}^{3}\right)}\right)\right)}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x}\\
\mathbf{elif}\;x \le 0.02029306521166552093604629192213906208053:\\
\;\;\;\;\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{\frac{{1}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)} - \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x}\\
\end{array}double f(double x) {
double r65562 = 1.0;
double r65563 = x;
double r65564 = cos(r65563);
double r65565 = r65562 - r65564;
double r65566 = sin(r65563);
double r65567 = r65565 / r65566;
return r65567;
}
double f(double x) {
double r65568 = x;
double r65569 = -0.02373580573239165;
bool r65570 = r65568 <= r65569;
double r65571 = 1.0;
double r65572 = 3.0;
double r65573 = pow(r65571, r65572);
double r65574 = cos(r65568);
double r65575 = pow(r65574, r65572);
double r65576 = r65573 - r65575;
double r65577 = expm1(r65576);
double r65578 = exp(r65577);
double r65579 = log(r65578);
double r65580 = log1p(r65579);
double r65581 = r65571 * r65574;
double r65582 = fma(r65574, r65574, r65581);
double r65583 = fma(r65571, r65571, r65582);
double r65584 = sin(r65568);
double r65585 = r65583 * r65584;
double r65586 = r65580 / r65585;
double r65587 = 0.02029306521166552;
bool r65588 = r65568 <= r65587;
double r65589 = 0.041666666666666664;
double r65590 = pow(r65568, r65572);
double r65591 = 0.004166666666666667;
double r65592 = 5.0;
double r65593 = pow(r65568, r65592);
double r65594 = 0.5;
double r65595 = r65594 * r65568;
double r65596 = fma(r65591, r65593, r65595);
double r65597 = fma(r65589, r65590, r65596);
double r65598 = r65571 + r65574;
double r65599 = r65571 * r65571;
double r65600 = fma(r65574, r65598, r65599);
double r65601 = r65573 / r65600;
double r65602 = r65575 / r65600;
double r65603 = r65601 - r65602;
double r65604 = r65603 / r65584;
double r65605 = r65588 ? r65597 : r65604;
double r65606 = r65570 ? r65586 : r65605;
return r65606;
}




Bits error versus x
| Original | 30.0 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.02373580573239165Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
rmApplied log1p-expm1-u1.0
rmApplied add-log-exp1.0
if -0.02373580573239165 < x < 0.02029306521166552Initial program 60.0
Taylor expanded around 0 0.0
Simplified0.0
if 0.02029306521166552 < x Initial program 0.9
rmApplied flip3--1.0
Simplified1.0
rmApplied div-sub1.0
Final simplification0.5
herbie shell --seed 2019353 +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)))