\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.019039573390386873:\\
\;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x} \cdot 1\\
\mathbf{elif}\;x \le 0.0240442248467046295:\\
\;\;\;\;\mathsf{fma}\left(0.04166666666666663, {x}^{3}, \mathsf{fma}\left(0.004166666666666624, {x}^{5}, 0.5 \cdot x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(e^{\frac{{1}^{3} - {\left(\cos x\right)}^{2} \cdot \cos x}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x}}\right)\\
\end{array}double f(double x) {
double r48628 = 1.0;
double r48629 = x;
double r48630 = cos(r48629);
double r48631 = r48628 - r48630;
double r48632 = sin(r48629);
double r48633 = r48631 / r48632;
return r48633;
}
double f(double x) {
double r48634 = x;
double r48635 = -0.019039573390386873;
bool r48636 = r48634 <= r48635;
double r48637 = 1.0;
double r48638 = 3.0;
double r48639 = pow(r48637, r48638);
double r48640 = cos(r48634);
double r48641 = pow(r48640, r48638);
double r48642 = r48639 - r48641;
double r48643 = r48637 * r48640;
double r48644 = fma(r48640, r48640, r48643);
double r48645 = fma(r48637, r48637, r48644);
double r48646 = sin(r48634);
double r48647 = r48645 * r48646;
double r48648 = r48642 / r48647;
double r48649 = 1.0;
double r48650 = r48648 * r48649;
double r48651 = 0.02404422484670463;
bool r48652 = r48634 <= r48651;
double r48653 = 0.04166666666666663;
double r48654 = pow(r48634, r48638);
double r48655 = 0.004166666666666624;
double r48656 = 5.0;
double r48657 = pow(r48634, r48656);
double r48658 = 0.5;
double r48659 = r48658 * r48634;
double r48660 = fma(r48655, r48657, r48659);
double r48661 = fma(r48653, r48654, r48660);
double r48662 = 2.0;
double r48663 = pow(r48640, r48662);
double r48664 = r48663 * r48640;
double r48665 = r48639 - r48664;
double r48666 = r48665 / r48647;
double r48667 = exp(r48666);
double r48668 = log(r48667);
double r48669 = r48652 ? r48661 : r48668;
double r48670 = r48636 ? r48650 : r48669;
return r48670;
}




Bits error versus x
| Original | 30.1 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.019039573390386873Initial program 0.9
rmApplied add-log-exp1.0
rmApplied flip3--1.1
Applied associate-/l/1.1
Simplified1.1
rmApplied *-un-lft-identity1.1
Applied exp-prod1.2
Applied log-pow1.0
Simplified1.0
if -0.019039573390386873 < x < 0.02404422484670463Initial program 60.0
rmApplied add-log-exp60.0
rmApplied flip3--60.0
Applied associate-/l/60.0
Simplified60.0
Taylor expanded around 0 0.0
Simplified0.0
if 0.02404422484670463 < x Initial program 0.9
rmApplied add-log-exp1.0
rmApplied flip3--1.1
Applied associate-/l/1.1
Simplified1.1
rmApplied add-cube-cbrt1.9
Applied unpow-prod-down1.8
Simplified1.3
Simplified1.1
Final simplification0.5
herbie shell --seed 2020033 +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)))