\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.01816359460916088:\\
\;\;\;\;\frac{1}{\sin x} - \cos x \cdot \frac{1}{\sin x}\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 6.0277248497108966 \cdot 10^{-4}:\\
\;\;\;\;\mathsf{fma}\left(0.041666666666666671, {x}^{3}, \mathsf{fma}\left(0.00416666666666666661, {x}^{5}, 0.5 \cdot x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\log \left(e^{1 - \cos x}\right)}{\sin x}\\
\end{array}double f(double x) {
double r62060 = 1.0;
double r62061 = x;
double r62062 = cos(r62061);
double r62063 = r62060 - r62062;
double r62064 = sin(r62061);
double r62065 = r62063 / r62064;
return r62065;
}
double f(double x) {
double r62066 = 1.0;
double r62067 = x;
double r62068 = cos(r62067);
double r62069 = r62066 - r62068;
double r62070 = sin(r62067);
double r62071 = r62069 / r62070;
double r62072 = -0.01816359460916088;
bool r62073 = r62071 <= r62072;
double r62074 = r62066 / r62070;
double r62075 = 1.0;
double r62076 = r62075 / r62070;
double r62077 = r62068 * r62076;
double r62078 = r62074 - r62077;
double r62079 = 0.0006027724849710897;
bool r62080 = r62071 <= r62079;
double r62081 = 0.04166666666666667;
double r62082 = 3.0;
double r62083 = pow(r62067, r62082);
double r62084 = 0.004166666666666667;
double r62085 = 5.0;
double r62086 = pow(r62067, r62085);
double r62087 = 0.5;
double r62088 = r62087 * r62067;
double r62089 = fma(r62084, r62086, r62088);
double r62090 = fma(r62081, r62083, r62089);
double r62091 = exp(r62069);
double r62092 = log(r62091);
double r62093 = r62092 / r62070;
double r62094 = r62080 ? r62090 : r62093;
double r62095 = r62073 ? r62078 : r62094;
return r62095;
}




Bits error versus x
| Original | 30.3 |
|---|---|
| Target | 0.0 |
| Herbie | 0.8 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.01816359460916088Initial program 0.8
rmApplied div-sub1.0
rmApplied div-inv0.9
if -0.01816359460916088 < (/ (- 1.0 (cos x)) (sin x)) < 0.0006027724849710897Initial program 59.6
rmApplied div-sub59.6
Taylor expanded around 0 0.5
Simplified0.5
if 0.0006027724849710897 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.0
rmApplied add-log-exp1.2
Applied add-log-exp1.2
Applied diff-log1.4
Simplified1.2
Final simplification0.8
herbie shell --seed 2020034 +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)))