\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.0444958089144920146:\\
\;\;\;\;\frac{\mathsf{fma}\left(1, 1, \cos x \cdot \left(\cos x + 1\right)\right) \cdot \left(1 - \cos x\right)}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x}\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 0.0033326395732868408:\\
\;\;\;\;\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}^{3} - \mathsf{log1p}\left(\mathsf{expm1}\left({\left(\cos x\right)}^{3}\right)\right)}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x}\\
\end{array}double f(double x) {
double r257 = 1.0;
double r258 = x;
double r259 = cos(r258);
double r260 = r257 - r259;
double r261 = sin(r258);
double r262 = r260 / r261;
return r262;
}
double f(double x) {
double r263 = 1.0;
double r264 = x;
double r265 = cos(r264);
double r266 = r263 - r265;
double r267 = sin(r264);
double r268 = r266 / r267;
double r269 = -0.044495808914492015;
bool r270 = r268 <= r269;
double r271 = r265 + r263;
double r272 = r265 * r271;
double r273 = fma(r263, r263, r272);
double r274 = r273 * r266;
double r275 = r263 * r265;
double r276 = fma(r265, r265, r275);
double r277 = fma(r263, r263, r276);
double r278 = r277 * r267;
double r279 = r274 / r278;
double r280 = 0.003332639573286841;
bool r281 = r268 <= r280;
double r282 = 0.041666666666666664;
double r283 = 3.0;
double r284 = pow(r264, r283);
double r285 = 0.004166666666666667;
double r286 = 5.0;
double r287 = pow(r264, r286);
double r288 = 0.5;
double r289 = r288 * r264;
double r290 = fma(r285, r287, r289);
double r291 = fma(r282, r284, r290);
double r292 = pow(r263, r283);
double r293 = pow(r265, r283);
double r294 = expm1(r293);
double r295 = log1p(r294);
double r296 = r292 - r295;
double r297 = r296 / r278;
double r298 = r281 ? r291 : r297;
double r299 = r270 ? r279 : r298;
return r299;
}




Bits error versus x
| Original | 29.4 |
|---|---|
| Target | 0.0 |
| Herbie | 1.0 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.044495808914492015Initial program 0.7
rmApplied flip3--0.8
Applied associate-/l/0.8
Simplified0.8
rmApplied difference-cubes0.8
Simplified0.8
if -0.044495808914492015 < (/ (- 1.0 (cos x)) (sin x)) < 0.003332639573286841Initial program 59.0
Taylor expanded around 0 1.1
Simplified1.1
if 0.003332639573286841 < (/ (- 1.0 (cos x)) (sin x)) Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
rmApplied log1p-expm1-u1.0
Final simplification1.0
herbie shell --seed 2020025 +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)))