\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := \left(\left(J \cdot -2\right) \cdot t_0\right) \cdot \mathsf{hypot}\left(1, \frac{U}{t_0 \cdot \left(J \cdot 2\right)}\right)\\
\mathbf{if}\;J \leq -2.282917432201898 \cdot 10^{-180}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;J \leq -3.970878637552764 \cdot 10^{-219}:\\
\;\;\;\;-U\\
\mathbf{elif}\;J \leq -1.3007612218473472 \cdot 10^{-306}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;J \leq 1.289364658539573 \cdot 10^{-207}:\\
\;\;\;\;U\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
(FPCore (J K U) :precision binary64 (* (* (* -2.0 J) (cos (/ K 2.0))) (sqrt (+ 1.0 (pow (/ U (* (* 2.0 J) (cos (/ K 2.0)))) 2.0)))))
(FPCore (J K U)
:precision binary64
(let* ((t_0 (cos (/ K 2.0)))
(t_1 (* (* (* J -2.0) t_0) (hypot 1.0 (/ U (* t_0 (* J 2.0)))))))
(if (<= J -2.282917432201898e-180)
t_1
(if (<= J -3.970878637552764e-219)
(- U)
(if (<= J -1.3007612218473472e-306)
t_1
(if (<= J 1.289364658539573e-207) U t_1))))))double code(double J, double K, double U) {
return ((-2.0 * J) * cos(K / 2.0)) * sqrt(1.0 + pow((U / ((2.0 * J) * cos(K / 2.0))), 2.0));
}
double code(double J, double K, double U) {
double t_0 = cos(K / 2.0);
double t_1 = ((J * -2.0) * t_0) * hypot(1.0, (U / (t_0 * (J * 2.0))));
double tmp;
if (J <= -2.282917432201898e-180) {
tmp = t_1;
} else if (J <= -3.970878637552764e-219) {
tmp = -U;
} else if (J <= -1.3007612218473472e-306) {
tmp = t_1;
} else if (J <= 1.289364658539573e-207) {
tmp = U;
} else {
tmp = t_1;
}
return tmp;
}



Bits error versus J



Bits error versus K



Bits error versus U
Results
if J < -2.2829174322018979e-180 or -3.97087863755276417e-219 < J < -1.30076122184734721e-306 or 1.289364658539573e-207 < J Initial program 15.4
Simplified6.0
if -2.2829174322018979e-180 < J < -3.97087863755276417e-219Initial program 38.5
Simplified21.8
Taylor expanded in J around 0 36.4
Simplified36.4
if -1.30076122184734721e-306 < J < 1.289364658539573e-207Initial program 43.3
Simplified29.8
Taylor expanded in U around -inf 34.2
Final simplification9.2
herbie shell --seed 2022103
(FPCore (J K U)
:name "Maksimov and Kolovsky, Equation (3)"
:precision binary64
(* (* (* -2.0 J) (cos (/ K 2.0))) (sqrt (+ 1.0 (pow (/ U (* (* 2.0 J) (cos (/ K 2.0)))) 2.0)))))