\frac{e^{x}}{e^{x} - 1}\begin{array}{l}
\mathbf{if}\;e^{x} \le 0.9972044245763829195539074135012924671173:\\
\;\;\;\;\frac{\frac{1}{1 + \sqrt{\frac{1}{e^{x}}}}}{\sqrt{1} - \sqrt{\frac{1}{e^{x}}}}\\
\mathbf{elif}\;e^{x} \le 1.00021080983059862390405214682687073946:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{x}\right) + \frac{1}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\log \left(e^{1 - \frac{1}{e^{x}}}\right)}\\
\end{array}double f(double x) {
double r75500 = x;
double r75501 = exp(r75500);
double r75502 = 1.0;
double r75503 = r75501 - r75502;
double r75504 = r75501 / r75503;
return r75504;
}
double f(double x) {
double r75505 = x;
double r75506 = exp(r75505);
double r75507 = 0.9972044245763829;
bool r75508 = r75506 <= r75507;
double r75509 = 1.0;
double r75510 = 1.0;
double r75511 = r75510 / r75506;
double r75512 = sqrt(r75511);
double r75513 = r75509 + r75512;
double r75514 = r75509 / r75513;
double r75515 = sqrt(r75509);
double r75516 = r75515 - r75512;
double r75517 = r75514 / r75516;
double r75518 = 1.0002108098305986;
bool r75519 = r75506 <= r75518;
double r75520 = 0.08333333333333333;
double r75521 = r75509 / r75505;
double r75522 = fma(r75520, r75505, r75521);
double r75523 = 0.5;
double r75524 = r75522 + r75523;
double r75525 = r75509 - r75511;
double r75526 = exp(r75525);
double r75527 = log(r75526);
double r75528 = r75509 / r75527;
double r75529 = r75519 ? r75524 : r75528;
double r75530 = r75508 ? r75517 : r75529;
return r75530;
}




Bits error versus x
| Original | 40.6 |
|---|---|
| Target | 40.2 |
| Herbie | 0.0 |
if (exp x) < 0.9972044245763829Initial program 0.0
rmApplied clear-num0.0
Simplified0.0
rmApplied add-sqr-sqrt0.0
Applied add-sqr-sqrt0.0
Applied difference-of-squares0.0
Applied associate-/r*0.0
Simplified0.0
if 0.9972044245763829 < (exp x) < 1.0002108098305986Initial program 62.4
Taylor expanded around 0 0.0
Simplified0.0
if 1.0002108098305986 < (exp x) Initial program 32.9
rmApplied clear-num32.9
Simplified1.5
rmApplied add-log-exp1.6
Applied add-log-exp1.6
Applied diff-log1.7
Simplified1.7
Final simplification0.0
herbie shell --seed 2019344 +o rules:numerics
(FPCore (x)
:name "expq2 (section 3.11)"
:precision binary64
:herbie-target
(/ 1 (- 1 (exp (- x))))
(/ (exp x) (- (exp x) 1)))