\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.02294790868899147795456627818566630594432:\\
\;\;\;\;\frac{1}{\frac{\sin x}{1 - \cos x}}\\
\mathbf{elif}\;x \le 0.02393964535351434871901510348379815695807:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(e^{\frac{1 - \cos x}{\sin x}}\right)\\
\end{array}double f(double x) {
double r59066 = 1.0;
double r59067 = x;
double r59068 = cos(r59067);
double r59069 = r59066 - r59068;
double r59070 = sin(r59067);
double r59071 = r59069 / r59070;
return r59071;
}
double f(double x) {
double r59072 = x;
double r59073 = -0.022947908688991478;
bool r59074 = r59072 <= r59073;
double r59075 = 1.0;
double r59076 = sin(r59072);
double r59077 = 1.0;
double r59078 = cos(r59072);
double r59079 = r59077 - r59078;
double r59080 = r59076 / r59079;
double r59081 = r59075 / r59080;
double r59082 = 0.02393964535351435;
bool r59083 = r59072 <= r59082;
double r59084 = 0.041666666666666664;
double r59085 = 3.0;
double r59086 = pow(r59072, r59085);
double r59087 = r59084 * r59086;
double r59088 = 0.004166666666666667;
double r59089 = 5.0;
double r59090 = pow(r59072, r59089);
double r59091 = r59088 * r59090;
double r59092 = 0.5;
double r59093 = r59092 * r59072;
double r59094 = r59091 + r59093;
double r59095 = r59087 + r59094;
double r59096 = r59079 / r59076;
double r59097 = exp(r59096);
double r59098 = log(r59097);
double r59099 = r59083 ? r59095 : r59098;
double r59100 = r59074 ? r59081 : r59099;
return r59100;
}




Bits error versus x
Results
| Original | 30.5 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.022947908688991478Initial program 0.9
rmApplied clear-num1.0
if -0.022947908688991478 < x < 0.02393964535351435Initial program 59.9
Taylor expanded around 0 0.0
if 0.02393964535351435 < x Initial program 0.9
rmApplied add-log-exp1.1
Final simplification0.5
herbie shell --seed 2019235
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))