
(FPCore (a b_2 c) :precision binary64 (/ (- (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))
double code(double a, double b_2, double c) {
return (-b_2 - sqrt(((b_2 * b_2) - (a * c)))) / a;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b_2, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
code = (-b_2 - sqrt(((b_2 * b_2) - (a * c)))) / a
end function
public static double code(double a, double b_2, double c) {
return (-b_2 - Math.sqrt(((b_2 * b_2) - (a * c)))) / a;
}
def code(a, b_2, c): return (-b_2 - math.sqrt(((b_2 * b_2) - (a * c)))) / a
function code(a, b_2, c) return Float64(Float64(Float64(-b_2) - sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c)))) / a) end
function tmp = code(a, b_2, c) tmp = (-b_2 - sqrt(((b_2 * b_2) - (a * c)))) / a; end
code[a_, b$95$2_, c_] := N[(N[((-b$95$2) - N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\_2\right) - \sqrt{b\_2 \cdot b\_2 - a \cdot c}}{a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b_2 c) :precision binary64 (/ (- (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))
double code(double a, double b_2, double c) {
return (-b_2 - sqrt(((b_2 * b_2) - (a * c)))) / a;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b_2, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
code = (-b_2 - sqrt(((b_2 * b_2) - (a * c)))) / a
end function
public static double code(double a, double b_2, double c) {
return (-b_2 - Math.sqrt(((b_2 * b_2) - (a * c)))) / a;
}
def code(a, b_2, c): return (-b_2 - math.sqrt(((b_2 * b_2) - (a * c)))) / a
function code(a, b_2, c) return Float64(Float64(Float64(-b_2) - sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c)))) / a) end
function tmp = code(a, b_2, c) tmp = (-b_2 - sqrt(((b_2 * b_2) - (a * c)))) / a; end
code[a_, b$95$2_, c_] := N[(N[((-b$95$2) - N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\_2\right) - \sqrt{b\_2 \cdot b\_2 - a \cdot c}}{a}
\end{array}
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -1.55e-96)
(* -0.5 (/ c b_2))
(if (<= b_2 5e+121)
(- (/ (* -1.0 b_2) a) (/ (pow (- (* b_2 b_2) (* a c)) 0.5) a))
(* -1.0 (/ (+ b_2 b_2) a)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.55e-96) {
tmp = -0.5 * (c / b_2);
} else if (b_2 <= 5e+121) {
tmp = ((-1.0 * b_2) / a) - (pow(((b_2 * b_2) - (a * c)), 0.5) / a);
} else {
tmp = -1.0 * ((b_2 + b_2) / a);
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b_2, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-1.55d-96)) then
tmp = (-0.5d0) * (c / b_2)
else if (b_2 <= 5d+121) then
tmp = (((-1.0d0) * b_2) / a) - ((((b_2 * b_2) - (a * c)) ** 0.5d0) / a)
else
tmp = (-1.0d0) * ((b_2 + b_2) / a)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.55e-96) {
tmp = -0.5 * (c / b_2);
} else if (b_2 <= 5e+121) {
tmp = ((-1.0 * b_2) / a) - (Math.pow(((b_2 * b_2) - (a * c)), 0.5) / a);
} else {
tmp = -1.0 * ((b_2 + b_2) / a);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -1.55e-96: tmp = -0.5 * (c / b_2) elif b_2 <= 5e+121: tmp = ((-1.0 * b_2) / a) - (math.pow(((b_2 * b_2) - (a * c)), 0.5) / a) else: tmp = -1.0 * ((b_2 + b_2) / a) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.55e-96) tmp = Float64(-0.5 * Float64(c / b_2)); elseif (b_2 <= 5e+121) tmp = Float64(Float64(Float64(-1.0 * b_2) / a) - Float64((Float64(Float64(b_2 * b_2) - Float64(a * c)) ^ 0.5) / a)); else tmp = Float64(-1.0 * Float64(Float64(b_2 + b_2) / a)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -1.55e-96) tmp = -0.5 * (c / b_2); elseif (b_2 <= 5e+121) tmp = ((-1.0 * b_2) / a) - ((((b_2 * b_2) - (a * c)) ^ 0.5) / a); else tmp = -1.0 * ((b_2 + b_2) / a); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.55e-96], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 5e+121], N[(N[(N[(-1.0 * b$95$2), $MachinePrecision] / a), $MachinePrecision] - N[(N[Power[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(-1.0 * N[(N[(b$95$2 + b$95$2), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -1.55 \cdot 10^{-96}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 5 \cdot 10^{+121}:\\
\;\;\;\;\frac{-1 \cdot b\_2}{a} - \frac{{\left(b\_2 \cdot b\_2 - a \cdot c\right)}^{0.5}}{a}\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{b\_2 + b\_2}{a}\\
\end{array}
\end{array}
if b_2 < -1.55e-96Initial program 17.4%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-/.f6487.7
Applied rewrites87.7%
if -1.55e-96 < b_2 < 5.00000000000000007e121Initial program 79.7%
Taylor expanded in c around 0
Applied rewrites79.7%
lift-/.f64N/A
lift--.f64N/A
div-subN/A
lower--.f64N/A
lower-/.f64N/A
lower-/.f6479.7
lift-sqrt.f64N/A
pow1/2N/A
lower-pow.f6479.7
Applied rewrites79.7%
if 5.00000000000000007e121 < b_2 Initial program 50.4%
Taylor expanded in a around 0
Applied rewrites94.2%
Final simplification85.7%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -1.55e-96)
(* -0.5 (/ c b_2))
(if (<= b_2 5e+121)
(- (/ (* -1.0 b_2) a) (/ (pow (- (* b_2 b_2) (* a c)) 0.5) a))
(fma (/ c b_2) 0.5 (* (/ b_2 a) -2.0)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.55e-96) {
tmp = -0.5 * (c / b_2);
} else if (b_2 <= 5e+121) {
tmp = ((-1.0 * b_2) / a) - (pow(((b_2 * b_2) - (a * c)), 0.5) / a);
} else {
tmp = fma((c / b_2), 0.5, ((b_2 / a) * -2.0));
}
return tmp;
}
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.55e-96) tmp = Float64(-0.5 * Float64(c / b_2)); elseif (b_2 <= 5e+121) tmp = Float64(Float64(Float64(-1.0 * b_2) / a) - Float64((Float64(Float64(b_2 * b_2) - Float64(a * c)) ^ 0.5) / a)); else tmp = fma(Float64(c / b_2), 0.5, Float64(Float64(b_2 / a) * -2.0)); end return tmp end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.55e-96], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 5e+121], N[(N[(N[(-1.0 * b$95$2), $MachinePrecision] / a), $MachinePrecision] - N[(N[Power[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b$95$2), $MachinePrecision] * 0.5 + N[(N[(b$95$2 / a), $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -1.55 \cdot 10^{-96}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 5 \cdot 10^{+121}:\\
\;\;\;\;\frac{-1 \cdot b\_2}{a} - \frac{{\left(b\_2 \cdot b\_2 - a \cdot c\right)}^{0.5}}{a}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{b\_2}, 0.5, \frac{b\_2}{a} \cdot -2\right)\\
\end{array}
\end{array}
if b_2 < -1.55e-96Initial program 17.4%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-/.f6487.7
Applied rewrites87.7%
if -1.55e-96 < b_2 < 5.00000000000000007e121Initial program 79.7%
Taylor expanded in c around 0
Applied rewrites79.7%
lift-/.f64N/A
lift--.f64N/A
div-subN/A
lower--.f64N/A
lower-/.f64N/A
lower-/.f6479.7
lift-sqrt.f64N/A
pow1/2N/A
lower-pow.f6479.7
Applied rewrites79.7%
if 5.00000000000000007e121 < b_2 Initial program 50.4%
Taylor expanded in c around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6494.2
Applied rewrites94.2%
Final simplification85.7%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -1.55e-96)
(* -0.5 (/ c b_2))
(if (<= b_2 5e+121)
(-
(/ (* -1.0 b_2) a)
(/ (pow (fma (pow b_2 1.0) (pow b_2 1.0) (* -1.0 (* c a))) 0.5) a))
(fma (/ c b_2) 0.5 (* (/ b_2 a) -2.0)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.55e-96) {
tmp = -0.5 * (c / b_2);
} else if (b_2 <= 5e+121) {
tmp = ((-1.0 * b_2) / a) - (pow(fma(pow(b_2, 1.0), pow(b_2, 1.0), (-1.0 * (c * a))), 0.5) / a);
} else {
tmp = fma((c / b_2), 0.5, ((b_2 / a) * -2.0));
}
return tmp;
}
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.55e-96) tmp = Float64(-0.5 * Float64(c / b_2)); elseif (b_2 <= 5e+121) tmp = Float64(Float64(Float64(-1.0 * b_2) / a) - Float64((fma((b_2 ^ 1.0), (b_2 ^ 1.0), Float64(-1.0 * Float64(c * a))) ^ 0.5) / a)); else tmp = fma(Float64(c / b_2), 0.5, Float64(Float64(b_2 / a) * -2.0)); end return tmp end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.55e-96], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 5e+121], N[(N[(N[(-1.0 * b$95$2), $MachinePrecision] / a), $MachinePrecision] - N[(N[Power[N[(N[Power[b$95$2, 1.0], $MachinePrecision] * N[Power[b$95$2, 1.0], $MachinePrecision] + N[(-1.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b$95$2), $MachinePrecision] * 0.5 + N[(N[(b$95$2 / a), $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -1.55 \cdot 10^{-96}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 5 \cdot 10^{+121}:\\
\;\;\;\;\frac{-1 \cdot b\_2}{a} - \frac{{\left(\mathsf{fma}\left({b\_2}^{1}, {b\_2}^{1}, -1 \cdot \left(c \cdot a\right)\right)\right)}^{0.5}}{a}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{b\_2}, 0.5, \frac{b\_2}{a} \cdot -2\right)\\
\end{array}
\end{array}
if b_2 < -1.55e-96Initial program 17.4%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-/.f6487.7
Applied rewrites87.7%
if -1.55e-96 < b_2 < 5.00000000000000007e121Initial program 79.7%
lift-/.f64N/A
lift-neg.f64N/A
lift--.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
div-subN/A
mul-1-negN/A
associate-*r/N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
Applied rewrites79.7%
if 5.00000000000000007e121 < b_2 Initial program 50.4%
Taylor expanded in c around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6494.2
Applied rewrites94.2%
Final simplification85.7%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -4e-310) (* -0.5 (/ c b_2)) (fma (/ c b_2) 0.5 (* (/ b_2 a) -2.0))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -4e-310) {
tmp = -0.5 * (c / b_2);
} else {
tmp = fma((c / b_2), 0.5, ((b_2 / a) * -2.0));
}
return tmp;
}
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -4e-310) tmp = Float64(-0.5 * Float64(c / b_2)); else tmp = fma(Float64(c / b_2), 0.5, Float64(Float64(b_2 / a) * -2.0)); end return tmp end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -4e-310], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision], N[(N[(c / b$95$2), $MachinePrecision] * 0.5 + N[(N[(b$95$2 / a), $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -4 \cdot 10^{-310}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b\_2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{b\_2}, 0.5, \frac{b\_2}{a} \cdot -2\right)\\
\end{array}
\end{array}
if b_2 < -3.999999999999988e-310Initial program 26.5%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-/.f6473.5
Applied rewrites73.5%
if -3.999999999999988e-310 < b_2 Initial program 72.9%
Taylor expanded in c around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6469.0
Applied rewrites69.0%
(FPCore (a b_2 c) :precision binary64 (* -0.5 (/ c b_2)))
double code(double a, double b_2, double c) {
return -0.5 * (c / b_2);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b_2, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
code = (-0.5d0) * (c / b_2)
end function
public static double code(double a, double b_2, double c) {
return -0.5 * (c / b_2);
}
def code(a, b_2, c): return -0.5 * (c / b_2)
function code(a, b_2, c) return Float64(-0.5 * Float64(c / b_2)) end
function tmp = code(a, b_2, c) tmp = -0.5 * (c / b_2); end
code[a_, b$95$2_, c_] := N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-0.5 \cdot \frac{c}{b\_2}
\end{array}
Initial program 48.4%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-/.f6439.8
Applied rewrites39.8%
herbie shell --seed 2025065
(FPCore (a b_2 c)
:name "quad2m (problem 3.2.1, negative)"
:precision binary64
:herbie-expected 10
:alt
(! :herbie-platform c (let ((sqtD (let ((x (* (sqrt (fabs a)) (sqrt (fabs c))))) (if (== (copysign a c) a) (* (sqrt (- (fabs b_2) x)) (sqrt (+ (fabs b_2) x))) (hypot b_2 x))))) (if (< b_2 0) (/ c (- sqtD b_2)) (/ (+ b_2 sqtD) (- a)))))
(/ (- (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))