(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
↓
(FPCore (a b)
:precision binary64
(if (<= (exp b) 0.0)
(/ 1.0 (+ (exp b) 1.0))
(if (<= (exp b) 1e+106)
(/ (exp a) (+ a (+ b 2.0)))
(+ (+ 1.0 (/ 1.0 (+ b 2.0))) -1.0))))
double code(double a, double b) {
return exp(a) / (exp(a) + exp(b));
}
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 (exp(b) <= 0.0d0) then
tmp = 1.0d0 / (exp(b) + 1.0d0)
else if (exp(b) <= 1d+106) then
tmp = exp(a) / (a + (b + 2.0d0))
else
tmp = (1.0d0 + (1.0d0 / (b + 2.0d0))) + (-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 (Math.exp(b) <= 0.0) {
tmp = 1.0 / (Math.exp(b) + 1.0);
} else if (Math.exp(b) <= 1e+106) {
tmp = Math.exp(a) / (a + (b + 2.0));
} else {
tmp = (1.0 + (1.0 / (b + 2.0))) + -1.0;
}
return tmp;
}
herbie shell --seed 2022317
(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))))