
(FPCore (t) :precision binary64 (- (* 1.7e+308 t) 1.7e+308))
double code(double t) {
return (1.7e+308 * t) - 1.7e+308;
}
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(t)
use fmin_fmax_functions
real(8), intent (in) :: t
code = (1.7d+308 * t) - 1.7d+308
end function
public static double code(double t) {
return (1.7e+308 * t) - 1.7e+308;
}
def code(t): return (1.7e+308 * t) - 1.7e+308
function code(t) return Float64(Float64(1.7e+308 * t) - 1.7e+308) end
function tmp = code(t) tmp = (1.7e+308 * t) - 1.7e+308; end
code[t_] := N[(N[(1.7e+308 * t), $MachinePrecision] - 1.7e+308), $MachinePrecision]
1.7 \cdot 10^{+308} \cdot t - 1.7 \cdot 10^{+308}
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (t) :precision binary64 (- (* 1.7e+308 t) 1.7e+308))
double code(double t) {
return (1.7e+308 * t) - 1.7e+308;
}
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(t)
use fmin_fmax_functions
real(8), intent (in) :: t
code = (1.7d+308 * t) - 1.7d+308
end function
public static double code(double t) {
return (1.7e+308 * t) - 1.7e+308;
}
def code(t): return (1.7e+308 * t) - 1.7e+308
function code(t) return Float64(Float64(1.7e+308 * t) - 1.7e+308) end
function tmp = code(t) tmp = (1.7e+308 * t) - 1.7e+308; end
code[t_] := N[(N[(1.7e+308 * t), $MachinePrecision] - 1.7e+308), $MachinePrecision]
1.7 \cdot 10^{+308} \cdot t - 1.7 \cdot 10^{+308}
(FPCore (t) :precision binary64 (* (- 1.7e+308 (/ 1.7e+308 t)) t))
double code(double t) {
return (1.7e+308 - (1.7e+308 / t)) * t;
}
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(t)
use fmin_fmax_functions
real(8), intent (in) :: t
code = (1.7d+308 - (1.7d+308 / t)) * t
end function
public static double code(double t) {
return (1.7e+308 - (1.7e+308 / t)) * t;
}
def code(t): return (1.7e+308 - (1.7e+308 / t)) * t
function code(t) return Float64(Float64(1.7e+308 - Float64(1.7e+308 / t)) * t) end
function tmp = code(t) tmp = (1.7e+308 - (1.7e+308 / t)) * t; end
code[t_] := N[(N[(1.7e+308 - N[(1.7e+308 / t), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision]
\left(1.7 \cdot 10^{+308} - \frac{1.7 \cdot 10^{+308}}{t}\right) \cdot t
Initial program 33.8%
Taylor expanded in t around inf
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f6499.3%
Applied rewrites99.3%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.3%
lift-*.f64N/A
lift-/.f64N/A
mult-flip-revN/A
lower-/.f6499.5%
Applied rewrites99.5%
(FPCore (t) :precision binary64 (fma t 1.7e+308 -1.7e+308))
double code(double t) {
return fma(t, 1.7e+308, -1.7e+308);
}
function code(t) return fma(t, 1.7e+308, -1.7e+308) end
code[t_] := N[(t * 1.7e+308 + -1.7e+308), $MachinePrecision]
\mathsf{fma}\left(t, 1.7 \cdot 10^{+308}, -1.7 \cdot 10^{+308}\right)
Initial program 33.8%
lift--.f64N/A
sub-negate-revN/A
lift-*.f64N/A
*-commutativeN/A
fp-cancel-sub-sign-invN/A
distribute-rgt1-inN/A
distribute-rgt-neg-inN/A
distribute-lft1-inN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-outN/A
remove-double-negN/A
lower-fma.f64N/A
metadata-eval99.6%
Applied rewrites99.6%
(FPCore (t) :precision binary64 (* t 1.7e+308))
double code(double t) {
return t * 1.7e+308;
}
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(t)
use fmin_fmax_functions
real(8), intent (in) :: t
code = t * 1.7d+308
end function
public static double code(double t) {
return t * 1.7e+308;
}
def code(t): return t * 1.7e+308
function code(t) return Float64(t * 1.7e+308) end
function tmp = code(t) tmp = t * 1.7e+308; end
code[t_] := N[(t * 1.7e+308), $MachinePrecision]
t \cdot 1.7 \cdot 10^{+308}
Initial program 33.8%
Taylor expanded in t around inf
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f6499.3%
Applied rewrites99.3%
Taylor expanded in t around inf
Applied rewrites33.8%
(FPCore (t) :precision binary64 -1.7e+308)
double code(double t) {
return -1.7e+308;
}
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(t)
use fmin_fmax_functions
real(8), intent (in) :: t
code = -1.7d+308
end function
public static double code(double t) {
return -1.7e+308;
}
def code(t): return -1.7e+308
function code(t) return -1.7e+308 end
function tmp = code(t) tmp = -1.7e+308; end
code[t_] := -1.7e+308
-1.7 \cdot 10^{+308}
Initial program 33.8%
Taylor expanded in t around 0
Applied rewrites0.0%
(FPCore (t) :precision binary64 (fma 1.7e+308 t (- 1.7e+308)))
double code(double t) {
return fma(1.7e+308, t, -1.7e+308);
}
function code(t) return fma(1.7e+308, t, Float64(-1.7e+308)) end
code[t_] := N[(1.7e+308 * t + (-1.7e+308)), $MachinePrecision]
\mathsf{fma}\left(1.7 \cdot 10^{+308}, t, -1.7 \cdot 10^{+308}\right)
herbie shell --seed 2025233
(FPCore (t)
:name "fma_test2"
:precision binary64
:pre (and (<= 1.9 t) (<= t 2.1))
:alt
(! :herbie-platform c (let ((x 170000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)) (fma x t (- x))))
(- (* 1.7e+308 t) 1.7e+308))