\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.01849382956573876121697530550136434612796:\\
\;\;\;\;1 \cdot \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}\\
\mathbf{elif}\;x \le 0.02173189858796714321598209096464415779337:\\
\;\;\;\;1 \cdot \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}:\\
\;\;\;\;1 \cdot \frac{\frac{{1}^{3} - {\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 r54192 = 1.0;
double r54193 = x;
double r54194 = cos(r54193);
double r54195 = r54192 - r54194;
double r54196 = sin(r54193);
double r54197 = r54195 / r54196;
return r54197;
}
double f(double x) {
double r54198 = x;
double r54199 = -0.01849382956573876;
bool r54200 = r54198 <= r54199;
double r54201 = 1.0;
double r54202 = 1.0;
double r54203 = 3.0;
double r54204 = pow(r54202, r54203);
double r54205 = cos(r54198);
double r54206 = pow(r54205, r54203);
double r54207 = r54204 - r54206;
double r54208 = r54202 * r54205;
double r54209 = fma(r54205, r54205, r54208);
double r54210 = fma(r54202, r54202, r54209);
double r54211 = sin(r54198);
double r54212 = r54210 * r54211;
double r54213 = r54207 / r54212;
double r54214 = r54201 * r54213;
double r54215 = 0.021731898587967143;
bool r54216 = r54198 <= r54215;
double r54217 = 0.041666666666666664;
double r54218 = pow(r54198, r54203);
double r54219 = 0.004166666666666667;
double r54220 = 5.0;
double r54221 = pow(r54198, r54220);
double r54222 = 0.5;
double r54223 = r54222 * r54198;
double r54224 = fma(r54219, r54221, r54223);
double r54225 = fma(r54217, r54218, r54224);
double r54226 = r54201 * r54225;
double r54227 = r54202 + r54205;
double r54228 = r54202 * r54202;
double r54229 = fma(r54205, r54227, r54228);
double r54230 = r54207 / r54229;
double r54231 = r54230 / r54211;
double r54232 = r54201 * r54231;
double r54233 = r54216 ? r54226 : r54232;
double r54234 = r54200 ? r54214 : r54233;
return r54234;
}




Bits error versus x
| Original | 30.2 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.01849382956573876Initial program 0.9
rmApplied *-un-lft-identity0.9
Applied *-un-lft-identity0.9
Applied times-frac0.9
Simplified0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
if -0.01849382956573876 < x < 0.021731898587967143Initial program 59.8
rmApplied *-un-lft-identity59.8
Applied *-un-lft-identity59.8
Applied times-frac59.8
Simplified59.8
rmApplied add-log-exp59.8
Taylor expanded around 0 0.0
Simplified0.0
if 0.021731898587967143 < x Initial program 0.9
rmApplied *-un-lft-identity0.9
Applied *-un-lft-identity0.9
Applied times-frac0.9
Simplified0.9
rmApplied flip3--1.0
Simplified1.0
Final simplification0.5
herbie shell --seed 2019354 +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)))