
(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]
\frac{\left(-b\_2\right) - \sqrt{b\_2 \cdot b\_2 - a \cdot c}}{a}
Herbie found 6 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]
\frac{\left(-b\_2\right) - \sqrt{b\_2 \cdot b\_2 - a \cdot c}}{a}
(FPCore (a b_2 c)
:precision binary64
(if (<=
b_2
-7136238463529799/2854495385411919762116571938898990272765493248)
(* -1/2 (/ c b_2))
(if (<=
b_2
50000000000000001642078124460246303949350628317980584775615671312937350344939399777200065781386370634197475239216121778932424531710574592)
(/ (- (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a)
(/ (* -2 b_2) a))))double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2.5e-30) {
tmp = -0.5 * (c / b_2);
} else if (b_2 <= 5e+136) {
tmp = (-b_2 - sqrt(((b_2 * b_2) - (a * c)))) / a;
} else {
tmp = (-2.0 * 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 <= (-2.5d-30)) then
tmp = (-0.5d0) * (c / b_2)
else if (b_2 <= 5d+136) then
tmp = (-b_2 - sqrt(((b_2 * b_2) - (a * c)))) / a
else
tmp = ((-2.0d0) * 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 <= -2.5e-30) {
tmp = -0.5 * (c / b_2);
} else if (b_2 <= 5e+136) {
tmp = (-b_2 - Math.sqrt(((b_2 * b_2) - (a * c)))) / a;
} else {
tmp = (-2.0 * b_2) / a;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -2.5e-30: tmp = -0.5 * (c / b_2) elif b_2 <= 5e+136: tmp = (-b_2 - math.sqrt(((b_2 * b_2) - (a * c)))) / a else: tmp = (-2.0 * b_2) / a return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -2.5e-30) tmp = Float64(-0.5 * Float64(c / b_2)); elseif (b_2 <= 5e+136) tmp = Float64(Float64(Float64(-b_2) - sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c)))) / a); else tmp = Float64(Float64(-2.0 * b_2) / a); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -2.5e-30) tmp = -0.5 * (c / b_2); elseif (b_2 <= 5e+136) tmp = (-b_2 - sqrt(((b_2 * b_2) - (a * c)))) / a; else tmp = (-2.0 * b_2) / a; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -7136238463529799/2854495385411919762116571938898990272765493248], N[(-1/2 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 50000000000000001642078124460246303949350628317980584775615671312937350344939399777200065781386370634197475239216121778932424531710574592], 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], N[(N[(-2 * b$95$2), $MachinePrecision] / a), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;b\_2 \leq \frac{-7136238463529799}{2854495385411919762116571938898990272765493248}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 50000000000000001642078124460246303949350628317980584775615671312937350344939399777200065781386370634197475239216121778932424531710574592:\\
\;\;\;\;\frac{\left(-b\_2\right) - \sqrt{b\_2 \cdot b\_2 - a \cdot c}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-2 \cdot b\_2}{a}\\
\end{array}
if b_2 < -2.4999999999999999e-30Initial program 51.5%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
if -2.4999999999999999e-30 < b_2 < 5.0000000000000002e136Initial program 51.5%
if 5.0000000000000002e136 < b_2 Initial program 51.5%
Taylor expanded in b_2 around inf
lower-*.f6435.3%
Applied rewrites35.3%
(FPCore (a b_2 c)
:precision binary64
(if (<=
b_2
-6850788924988607/2854495385411919762116571938898990272765493248)
(* -1/2 (/ c b_2))
(if (<= b_2 130000000000000)
(/ (- (- b_2) (sqrt (- (* a c)))) a)
(/ (* -2 b_2) a))))double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2.4e-30) {
tmp = -0.5 * (c / b_2);
} else if (b_2 <= 1.3e+14) {
tmp = (-b_2 - sqrt(-(a * c))) / a;
} else {
tmp = (-2.0 * 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 <= (-2.4d-30)) then
tmp = (-0.5d0) * (c / b_2)
else if (b_2 <= 1.3d+14) then
tmp = (-b_2 - sqrt(-(a * c))) / a
else
tmp = ((-2.0d0) * 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 <= -2.4e-30) {
tmp = -0.5 * (c / b_2);
} else if (b_2 <= 1.3e+14) {
tmp = (-b_2 - Math.sqrt(-(a * c))) / a;
} else {
tmp = (-2.0 * b_2) / a;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -2.4e-30: tmp = -0.5 * (c / b_2) elif b_2 <= 1.3e+14: tmp = (-b_2 - math.sqrt(-(a * c))) / a else: tmp = (-2.0 * b_2) / a return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -2.4e-30) tmp = Float64(-0.5 * Float64(c / b_2)); elseif (b_2 <= 1.3e+14) tmp = Float64(Float64(Float64(-b_2) - sqrt(Float64(-Float64(a * c)))) / a); else tmp = Float64(Float64(-2.0 * b_2) / a); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -2.4e-30) tmp = -0.5 * (c / b_2); elseif (b_2 <= 1.3e+14) tmp = (-b_2 - sqrt(-(a * c))) / a; else tmp = (-2.0 * b_2) / a; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -6850788924988607/2854495385411919762116571938898990272765493248], N[(-1/2 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 130000000000000], N[(N[((-b$95$2) - N[Sqrt[(-N[(a * c), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[(N[(-2 * b$95$2), $MachinePrecision] / a), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;b\_2 \leq \frac{-6850788924988607}{2854495385411919762116571938898990272765493248}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 130000000000000:\\
\;\;\;\;\frac{\left(-b\_2\right) - \sqrt{-a \cdot c}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-2 \cdot b\_2}{a}\\
\end{array}
if b_2 < -2.3999999999999998e-30Initial program 51.5%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
if -2.3999999999999998e-30 < b_2 < 1.3e14Initial program 51.5%
Taylor expanded in b_2 around 0
lower-sqrt.f64N/A
lower-neg.f64N/A
lower-*.f6432.9%
Applied rewrites32.9%
if 1.3e14 < b_2 Initial program 51.5%
Taylor expanded in b_2 around inf
lower-*.f6435.3%
Applied rewrites35.3%
(FPCore (a b_2 c)
:precision binary64
(if (<=
b_2
-7136238463529799/2854495385411919762116571938898990272765493248)
(* -1/2 (/ c b_2))
(if (<= b_2 200000) (* c (sqrt (/ -1 (* a c)))) (/ (* -2 b_2) a))))double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2.5e-30) {
tmp = -0.5 * (c / b_2);
} else if (b_2 <= 200000.0) {
tmp = c * sqrt((-1.0 / (a * c)));
} else {
tmp = (-2.0 * 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 <= (-2.5d-30)) then
tmp = (-0.5d0) * (c / b_2)
else if (b_2 <= 200000.0d0) then
tmp = c * sqrt(((-1.0d0) / (a * c)))
else
tmp = ((-2.0d0) * 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 <= -2.5e-30) {
tmp = -0.5 * (c / b_2);
} else if (b_2 <= 200000.0) {
tmp = c * Math.sqrt((-1.0 / (a * c)));
} else {
tmp = (-2.0 * b_2) / a;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -2.5e-30: tmp = -0.5 * (c / b_2) elif b_2 <= 200000.0: tmp = c * math.sqrt((-1.0 / (a * c))) else: tmp = (-2.0 * b_2) / a return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -2.5e-30) tmp = Float64(-0.5 * Float64(c / b_2)); elseif (b_2 <= 200000.0) tmp = Float64(c * sqrt(Float64(-1.0 / Float64(a * c)))); else tmp = Float64(Float64(-2.0 * b_2) / a); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -2.5e-30) tmp = -0.5 * (c / b_2); elseif (b_2 <= 200000.0) tmp = c * sqrt((-1.0 / (a * c))); else tmp = (-2.0 * b_2) / a; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -7136238463529799/2854495385411919762116571938898990272765493248], N[(-1/2 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 200000], N[(c * N[Sqrt[N[(-1 / N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(-2 * b$95$2), $MachinePrecision] / a), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;b\_2 \leq \frac{-7136238463529799}{2854495385411919762116571938898990272765493248}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 200000:\\
\;\;\;\;c \cdot \sqrt{\frac{-1}{a \cdot c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-2 \cdot b\_2}{a}\\
\end{array}
if b_2 < -2.4999999999999999e-30Initial program 51.5%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
if -2.4999999999999999e-30 < b_2 < 2e5Initial program 51.5%
Taylor expanded in a around -inf
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6417.0%
Applied rewrites17.0%
Taylor expanded in c around inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-*.f6427.3%
Applied rewrites27.3%
if 2e5 < b_2 Initial program 51.5%
Taylor expanded in b_2 around inf
lower-*.f6435.3%
Applied rewrites35.3%
(FPCore (a b_2 c)
:precision binary64
(if (<=
b_2
-1644522595740685/149502054158244092924433911175587146134101311725520811805218980426523448679093940601025751001247626027946551200107541538756647476310030352326743206124657514520641361489437161884315621531536712531968)
(* -1/2 (/ c b_2))
(if (<=
b_2
6585090523536935/173291855882550928723650886508942731464777317210988535948154973788413831737851601439998400381508723631086950685087723239310884864)
(sqrt (/ (- c) a))
(/ (* -2 b_2) a))))double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.1e-182) {
tmp = -0.5 * (c / b_2);
} else if (b_2 <= 3.8e-113) {
tmp = sqrt((-c / a));
} else {
tmp = (-2.0 * 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.1d-182)) then
tmp = (-0.5d0) * (c / b_2)
else if (b_2 <= 3.8d-113) then
tmp = sqrt((-c / a))
else
tmp = ((-2.0d0) * 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.1e-182) {
tmp = -0.5 * (c / b_2);
} else if (b_2 <= 3.8e-113) {
tmp = Math.sqrt((-c / a));
} else {
tmp = (-2.0 * b_2) / a;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -1.1e-182: tmp = -0.5 * (c / b_2) elif b_2 <= 3.8e-113: tmp = math.sqrt((-c / a)) else: tmp = (-2.0 * b_2) / a return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.1e-182) tmp = Float64(-0.5 * Float64(c / b_2)); elseif (b_2 <= 3.8e-113) tmp = sqrt(Float64(Float64(-c) / a)); else tmp = Float64(Float64(-2.0 * b_2) / a); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -1.1e-182) tmp = -0.5 * (c / b_2); elseif (b_2 <= 3.8e-113) tmp = sqrt((-c / a)); else tmp = (-2.0 * b_2) / a; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1644522595740685/149502054158244092924433911175587146134101311725520811805218980426523448679093940601025751001247626027946551200107541538756647476310030352326743206124657514520641361489437161884315621531536712531968], N[(-1/2 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 6585090523536935/173291855882550928723650886508942731464777317210988535948154973788413831737851601439998400381508723631086950685087723239310884864], N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision], N[(N[(-2 * b$95$2), $MachinePrecision] / a), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;b\_2 \leq \frac{-1644522595740685}{149502054158244092924433911175587146134101311725520811805218980426523448679093940601025751001247626027946551200107541538756647476310030352326743206124657514520641361489437161884315621531536712531968}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq \frac{6585090523536935}{173291855882550928723650886508942731464777317210988535948154973788413831737851601439998400381508723631086950685087723239310884864}:\\
\;\;\;\;\sqrt{\frac{-c}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-2 \cdot b\_2}{a}\\
\end{array}
if b_2 < -1.1e-182Initial program 51.5%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
if -1.1e-182 < b_2 < 3.7999999999999998e-113Initial program 51.5%
Taylor expanded in a around -inf
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6417.0%
Applied rewrites17.0%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lower-/.f64N/A
*-rgt-identityN/A
metadata-evalN/A
distribute-rgt-neg-outN/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-outN/A
metadata-evalN/A
*-rgt-identity17.0%
Applied rewrites17.0%
if 3.7999999999999998e-113 < b_2 Initial program 51.5%
Taylor expanded in b_2 around inf
lower-*.f6435.3%
Applied rewrites35.3%
(FPCore (a b_2 c)
:precision binary64
(if (<=
b_2
-1141319417461387/184083777009901148951480851536796132722480842643692193047992403105518260024832986247893480778145316885626996612988306798242600723265962621432675768974821503362834322867062256922933472871676000378319956942935045907290266298718681990629287025193807090855270922941016369397705979841003229496151404881535205516509184)
(* -1/2 (/ c b_2))
(/ (* -2 b_2) a)))double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -6.2e-297) {
tmp = -0.5 * (c / b_2);
} else {
tmp = (-2.0 * 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 <= (-6.2d-297)) then
tmp = (-0.5d0) * (c / b_2)
else
tmp = ((-2.0d0) * 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 <= -6.2e-297) {
tmp = -0.5 * (c / b_2);
} else {
tmp = (-2.0 * b_2) / a;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -6.2e-297: tmp = -0.5 * (c / b_2) else: tmp = (-2.0 * b_2) / a return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -6.2e-297) tmp = Float64(-0.5 * Float64(c / b_2)); else tmp = Float64(Float64(-2.0 * b_2) / a); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -6.2e-297) tmp = -0.5 * (c / b_2); else tmp = (-2.0 * b_2) / a; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1141319417461387/184083777009901148951480851536796132722480842643692193047992403105518260024832986247893480778145316885626996612988306798242600723265962621432675768974821503362834322867062256922933472871676000378319956942935045907290266298718681990629287025193807090855270922941016369397705979841003229496151404881535205516509184], N[(-1/2 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision], N[(N[(-2 * b$95$2), $MachinePrecision] / a), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;b\_2 \leq \frac{-1141319417461387}{184083777009901148951480851536796132722480842643692193047992403105518260024832986247893480778145316885626996612988306798242600723265962621432675768974821503362834322867062256922933472871676000378319956942935045907290266298718681990629287025193807090855270922941016369397705979841003229496151404881535205516509184}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{c}{b\_2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-2 \cdot b\_2}{a}\\
\end{array}
if b_2 < -6.1999999999999993e-297Initial program 51.5%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
if -6.1999999999999993e-297 < b_2 Initial program 51.5%
Taylor expanded in b_2 around inf
lower-*.f6435.3%
Applied rewrites35.3%
(FPCore (a b_2 c) :precision binary64 (* -1/2 (/ 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[(-1/2 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]
\frac{-1}{2} \cdot \frac{c}{b\_2}
Initial program 51.5%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
herbie shell --seed 2025285 -o generate:evaluate
(FPCore (a b_2 c)
:name "quad2m (problem 3.2.1, negative)"
:precision binary64
:herbie-expected 10
(/ (- (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))