\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.0195414650842071873:\\
\;\;\;\;\frac{\mathsf{log1p}\left(\mathsf{expm1}\left(1 - \cos x\right)\right)}{\sin x}\\
\mathbf{elif}\;x \le 0.023267676544555443:\\
\;\;\;\;\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{{e}^{\left(\log \left(1 - \cos x\right)\right)}}{\sin x}\\
\end{array}double f(double x) {
double r83934 = 1.0;
double r83935 = x;
double r83936 = cos(r83935);
double r83937 = r83934 - r83936;
double r83938 = sin(r83935);
double r83939 = r83937 / r83938;
return r83939;
}
double f(double x) {
double r83940 = x;
double r83941 = -0.019541465084207187;
bool r83942 = r83940 <= r83941;
double r83943 = 1.0;
double r83944 = cos(r83940);
double r83945 = r83943 - r83944;
double r83946 = expm1(r83945);
double r83947 = log1p(r83946);
double r83948 = sin(r83940);
double r83949 = r83947 / r83948;
double r83950 = 0.023267676544555443;
bool r83951 = r83940 <= r83950;
double r83952 = 0.041666666666666664;
double r83953 = 3.0;
double r83954 = pow(r83940, r83953);
double r83955 = 0.004166666666666667;
double r83956 = 5.0;
double r83957 = pow(r83940, r83956);
double r83958 = 0.5;
double r83959 = r83958 * r83940;
double r83960 = fma(r83955, r83957, r83959);
double r83961 = fma(r83952, r83954, r83960);
double r83962 = exp(1.0);
double r83963 = log(r83945);
double r83964 = pow(r83962, r83963);
double r83965 = r83964 / r83948;
double r83966 = r83951 ? r83961 : r83965;
double r83967 = r83942 ? r83949 : r83966;
return r83967;
}




Bits error versus x
| Original | 30.1 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.019541465084207187Initial program 0.9
rmApplied add-exp-log0.9
rmApplied pow10.9
Applied log-pow0.9
Applied exp-prod0.9
Simplified0.9
rmApplied log1p-expm1-u0.9
Simplified0.9
if -0.019541465084207187 < x < 0.023267676544555443Initial program 60.0
Taylor expanded around 0 0.0
Simplified0.0
if 0.023267676544555443 < x Initial program 0.9
rmApplied add-exp-log0.9
rmApplied pow10.9
Applied log-pow0.9
Applied exp-prod1.0
Simplified1.0
Final simplification0.5
herbie shell --seed 2020047 +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)))