\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 r58008 = 1.0;
double r58009 = x;
double r58010 = cos(r58009);
double r58011 = r58008 - r58010;
double r58012 = sin(r58009);
double r58013 = r58011 / r58012;
return r58013;
}
double f(double x) {
double r58014 = x;
double r58015 = -0.02373580573239165;
bool r58016 = r58014 <= r58015;
double r58017 = 1.0;
double r58018 = 3.0;
double r58019 = pow(r58017, r58018);
double r58020 = cos(r58014);
double r58021 = pow(r58020, r58018);
double r58022 = r58019 - r58021;
double r58023 = expm1(r58022);
double r58024 = exp(r58023);
double r58025 = log(r58024);
double r58026 = log1p(r58025);
double r58027 = r58017 * r58020;
double r58028 = fma(r58020, r58020, r58027);
double r58029 = fma(r58017, r58017, r58028);
double r58030 = sin(r58014);
double r58031 = r58029 * r58030;
double r58032 = r58026 / r58031;
double r58033 = 0.02029306521166552;
bool r58034 = r58014 <= r58033;
double r58035 = 0.041666666666666664;
double r58036 = pow(r58014, r58018);
double r58037 = 0.004166666666666667;
double r58038 = 5.0;
double r58039 = pow(r58014, r58038);
double r58040 = 0.5;
double r58041 = r58040 * r58014;
double r58042 = fma(r58037, r58039, r58041);
double r58043 = fma(r58035, r58036, r58042);
double r58044 = r58017 + r58020;
double r58045 = r58017 * r58017;
double r58046 = fma(r58020, r58044, r58045);
double r58047 = r58019 / r58046;
double r58048 = r58021 / r58046;
double r58049 = r58047 - r58048;
double r58050 = r58049 / r58030;
double r58051 = r58034 ? r58043 : r58050;
double r58052 = r58016 ? r58032 : r58051;
return r58052;
}




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)))