\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.002585231506460964:\\
\;\;\;\;\frac{e^{\log \left(1 - \cos x\right)}}{\sin x}\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 1.53832503201192376 \cdot 10^{-8}:\\
\;\;\;\;\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^{\log \left({1}^{3} - {\left(\cos x\right)}^{3}\right)}}{\mathsf{fma}\left(1, 1, \cos x \cdot \left(\cos x + 1\right)\right) \cdot \sin x}\\
\end{array}double f(double x) {
double r75022 = 1.0;
double r75023 = x;
double r75024 = cos(r75023);
double r75025 = r75022 - r75024;
double r75026 = sin(r75023);
double r75027 = r75025 / r75026;
return r75027;
}
double f(double x) {
double r75028 = 1.0;
double r75029 = x;
double r75030 = cos(r75029);
double r75031 = r75028 - r75030;
double r75032 = sin(r75029);
double r75033 = r75031 / r75032;
double r75034 = -0.0025852315064609638;
bool r75035 = r75033 <= r75034;
double r75036 = log(r75031);
double r75037 = exp(r75036);
double r75038 = r75037 / r75032;
double r75039 = 1.5383250320119238e-08;
bool r75040 = r75033 <= r75039;
double r75041 = 0.041666666666666664;
double r75042 = 3.0;
double r75043 = pow(r75029, r75042);
double r75044 = 0.004166666666666667;
double r75045 = 5.0;
double r75046 = pow(r75029, r75045);
double r75047 = 0.5;
double r75048 = r75047 * r75029;
double r75049 = fma(r75044, r75046, r75048);
double r75050 = fma(r75041, r75043, r75049);
double r75051 = pow(r75028, r75042);
double r75052 = pow(r75030, r75042);
double r75053 = r75051 - r75052;
double r75054 = log(r75053);
double r75055 = exp(r75054);
double r75056 = r75030 + r75028;
double r75057 = r75030 * r75056;
double r75058 = fma(r75028, r75028, r75057);
double r75059 = r75058 * r75032;
double r75060 = r75055 / r75059;
double r75061 = r75040 ? r75050 : r75060;
double r75062 = r75035 ? r75038 : r75061;
return r75062;
}




Bits error versus x
| Original | 30.0 |
|---|---|
| Target | 0.0 |
| Herbie | 0.6 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.0025852315064609638Initial program 0.9
rmApplied add-exp-log0.9
rmApplied *-un-lft-identity0.9
if -0.0025852315064609638 < (/ (- 1.0 (cos x)) (sin x)) < 1.5383250320119238e-08Initial program 60.3
rmApplied clear-num60.3
Taylor expanded around 0 0.1
Simplified0.1
if 1.5383250320119238e-08 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.3
rmApplied add-exp-log1.3
rmApplied *-un-lft-identity1.3
rmApplied flip3--1.4
Applied log-div1.5
Applied exp-diff1.4
Applied associate-/l/1.4
Simplified1.4
Final simplification0.6
herbie shell --seed 2019199 +o rules:numerics
(FPCore (x)
:name "tanhf (example 3.4)"
:herbie-expected 2
:herbie-target
(tan (/ x 2.0))
(/ (- 1.0 (cos x)) (sin x)))