\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.023254737060871069620482387563242809847:\\
\;\;\;\;\frac{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}{\frac{\sin x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \left(1 + \cos x\right)\right)}{1 - \cos x}}\\
\mathbf{elif}\;x \le 0.02350362276191214974674359439177351305261:\\
\;\;\;\;\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{expm1}\left(\mathsf{log1p}\left({\left(\cos x\right)}^{3}\right)\right)}{\sin x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \frac{1 \cdot 1 - {\left(\cos x\right)}^{2}}{1 - \cos x}\right)}\\
\end{array}double f(double x) {
double r57245 = 1.0;
double r57246 = x;
double r57247 = cos(r57246);
double r57248 = r57245 - r57247;
double r57249 = sin(r57246);
double r57250 = r57248 / r57249;
return r57250;
}
double f(double x) {
double r57251 = x;
double r57252 = -0.02325473706087107;
bool r57253 = r57251 <= r57252;
double r57254 = 1.0;
double r57255 = r57254 * r57254;
double r57256 = cos(r57251);
double r57257 = r57256 * r57256;
double r57258 = r57254 * r57256;
double r57259 = r57257 + r57258;
double r57260 = r57255 + r57259;
double r57261 = sin(r57251);
double r57262 = r57254 + r57256;
double r57263 = r57256 * r57262;
double r57264 = fma(r57254, r57254, r57263);
double r57265 = r57261 * r57264;
double r57266 = r57254 - r57256;
double r57267 = r57265 / r57266;
double r57268 = r57260 / r57267;
double r57269 = 0.02350362276191215;
bool r57270 = r57251 <= r57269;
double r57271 = 0.041666666666666664;
double r57272 = 3.0;
double r57273 = pow(r57251, r57272);
double r57274 = 0.004166666666666667;
double r57275 = 5.0;
double r57276 = pow(r57251, r57275);
double r57277 = 0.5;
double r57278 = r57277 * r57251;
double r57279 = fma(r57274, r57276, r57278);
double r57280 = fma(r57271, r57273, r57279);
double r57281 = pow(r57254, r57272);
double r57282 = pow(r57256, r57272);
double r57283 = log1p(r57282);
double r57284 = expm1(r57283);
double r57285 = r57281 - r57284;
double r57286 = 2.0;
double r57287 = pow(r57256, r57286);
double r57288 = r57255 - r57287;
double r57289 = r57288 / r57266;
double r57290 = r57256 * r57289;
double r57291 = fma(r57254, r57254, r57290);
double r57292 = r57261 * r57291;
double r57293 = r57285 / r57292;
double r57294 = r57270 ? r57280 : r57293;
double r57295 = r57253 ? r57268 : r57294;
return r57295;
}




Bits error versus x
| Original | 30.3 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.02325473706087107Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
rmApplied difference-cubes1.0
Applied associate-/l*1.0
if -0.02325473706087107 < x < 0.02350362276191215Initial program 60.0
Taylor expanded around 0 0.0
Simplified0.0
if 0.02350362276191215 < x Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
rmApplied expm1-log1p-u1.0
rmApplied flip-+1.0
Simplified1.0
Final simplification0.5
herbie shell --seed 2019303 +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)))