\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.02243905911353925516915630566927575273439:\\
\;\;\;\;\frac{1}{\frac{\sin x}{e^{\log \left(1 - \cos x\right)}}}\\
\mathbf{elif}\;x \le 0.02429226137720021799770719894695503171533:\\
\;\;\;\;\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{1}{\sin x} \cdot \left(1 - \cos x\right)\\
\end{array}double f(double x) {
double r40812 = 1.0;
double r40813 = x;
double r40814 = cos(r40813);
double r40815 = r40812 - r40814;
double r40816 = sin(r40813);
double r40817 = r40815 / r40816;
return r40817;
}
double f(double x) {
double r40818 = x;
double r40819 = -0.022439059113539255;
bool r40820 = r40818 <= r40819;
double r40821 = 1.0;
double r40822 = sin(r40818);
double r40823 = 1.0;
double r40824 = cos(r40818);
double r40825 = r40823 - r40824;
double r40826 = log(r40825);
double r40827 = exp(r40826);
double r40828 = r40822 / r40827;
double r40829 = r40821 / r40828;
double r40830 = 0.024292261377200218;
bool r40831 = r40818 <= r40830;
double r40832 = 0.041666666666666664;
double r40833 = 3.0;
double r40834 = pow(r40818, r40833);
double r40835 = 0.004166666666666667;
double r40836 = 5.0;
double r40837 = pow(r40818, r40836);
double r40838 = 0.5;
double r40839 = r40838 * r40818;
double r40840 = fma(r40835, r40837, r40839);
double r40841 = fma(r40832, r40834, r40840);
double r40842 = r40821 / r40822;
double r40843 = r40842 * r40825;
double r40844 = r40831 ? r40841 : r40843;
double r40845 = r40820 ? r40829 : r40844;
return r40845;
}




Bits error versus x
| Original | 30.3 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.022439059113539255Initial program 1.0
rmApplied clear-num1.0
rmApplied add-exp-log1.0
if -0.022439059113539255 < x < 0.024292261377200218Initial program 60.0
Taylor expanded around 0 0.0
Simplified0.0
if 0.024292261377200218 < x Initial program 0.9
rmApplied clear-num0.9
rmApplied div-inv1.0
Applied add-cube-cbrt1.0
Applied times-frac1.0
Simplified1.0
Simplified1.0
Final simplification0.5
herbie shell --seed 2019356 +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)))