\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -2.79464116829470944 \cdot 10^{-99} \lor \neg \left(\varepsilon \le 6.98350813945844421 \cdot 10^{-29}\right):\\
\;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x}{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \cos x}\\
\mathbf{else}:\\
\;\;\;\;\left(\varepsilon \cdot x\right) \cdot \left(x + \varepsilon\right) + \varepsilon\\
\end{array}double code(double x, double eps) {
return (tan((x + eps)) - tan(x));
}
double code(double x, double eps) {
double VAR;
if (((eps <= -2.7946411682947094e-99) || !(eps <= 6.983508139458444e-29))) {
VAR = ((((tan(x) + tan(eps)) * cos(x)) - ((1.0 - (tan(x) * tan(eps))) * sin(x))) / ((1.0 - (tan(x) * tan(eps))) * cos(x)));
} else {
VAR = (((eps * x) * (x + eps)) + eps);
}
return VAR;
}




Bits error versus x




Bits error versus eps
Results
| Original | 36.8 |
|---|---|
| Target | 14.9 |
| Herbie | 15.6 |
if eps < -2.7946411682947094e-99 or 6.983508139458444e-29 < eps Initial program 30.2
rmApplied tan-quot30.1
Applied tan-sum5.4
Applied frac-sub5.4
if -2.7946411682947094e-99 < eps < 6.983508139458444e-29Initial program 46.6
Taylor expanded around 0 31.0
Simplified30.8
Final simplification15.6
herbie shell --seed 2020079
(FPCore (x eps)
:name "2tan (problem 3.3.2)"
:precision binary64
:herbie-target
(/ (sin eps) (* (cos x) (cos (+ x eps))))
(- (tan (+ x eps)) (tan x)))