real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = exp(a) / (exp(a) + exp(b))
end function
↓
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if ((b <= (-63000.0d0)) .or. (.not. (b <= 1.45d-11))) then
tmp = 1.0d0 / (exp(b) + 1.0d0)
else
tmp = exp(a) / (exp(a) + 1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
return Math.exp(a) / (Math.exp(a) + Math.exp(b));
}
↓
public static double code(double a, double b) {
double tmp;
if ((b <= -63000.0) || !(b <= 1.45e-11)) {
tmp = 1.0 / (Math.exp(b) + 1.0);
} else {
tmp = Math.exp(a) / (Math.exp(a) + 1.0);
}
return tmp;
}
herbie shell --seed 2023083
(FPCore (a b)
:name "Quotient of sum of exps"
:precision binary64
:herbie-target
(/ 1.0 (+ 1.0 (exp (- b a))))
(/ (exp a) (+ (exp a) (exp b))))