(FPCore (A B C)
:precision binary64
(*
180.0
(/
(atan (* (/ 1.0 B) (- (- C A) (sqrt (+ (pow (- A C) 2.0) (pow B 2.0))))))
PI)))
↓
(FPCore (A B C)
:precision binary64
(if (<= A -1.2e+64)
(* 180.0 (/ (atan (/ (* 0.5 B) A)) PI))
(* 180.0 (/ (atan (/ (- (- C A) (hypot B (- A C))) B)) PI))))
double code(double A, double B, double C) {
return 180.0 * (atan(((1.0 / B) * ((C - A) - sqrt((pow((A - C), 2.0) + pow(B, 2.0)))))) / ((double) M_PI));
}
↓
double code(double A, double B, double C) {
double tmp;
if (A <= -1.2e+64) {
tmp = 180.0 * (atan(((0.5 * B) / A)) / ((double) M_PI));
} else {
tmp = 180.0 * (atan((((C - A) - hypot(B, (A - C))) / B)) / ((double) M_PI));
}
return tmp;
}
public static double code(double A, double B, double C) {
return 180.0 * (Math.atan(((1.0 / B) * ((C - A) - Math.sqrt((Math.pow((A - C), 2.0) + Math.pow(B, 2.0)))))) / Math.PI);
}
↓
public static double code(double A, double B, double C) {
double tmp;
if (A <= -1.2e+64) {
tmp = 180.0 * (Math.atan(((0.5 * B) / A)) / Math.PI);
} else {
tmp = 180.0 * (Math.atan((((C - A) - Math.hypot(B, (A - C))) / B)) / Math.PI);
}
return tmp;
}
def code(A, B, C):
tmp = 0
if A <= -1.2e+64:
tmp = 180.0 * (math.atan(((0.5 * B) / A)) / math.pi)
else:
tmp = 180.0 * (math.atan((((C - A) - math.hypot(B, (A - C))) / B)) / math.pi)
return tmp
function code(A, B, C)
return Float64(180.0 * Float64(atan(Float64(Float64(1.0 / B) * Float64(Float64(C - A) - sqrt(Float64((Float64(A - C) ^ 2.0) + (B ^ 2.0)))))) / pi))
end
↓
function code(A, B, C)
tmp = 0.0
if (A <= -1.2e+64)
tmp = Float64(180.0 * Float64(atan(Float64(Float64(0.5 * B) / A)) / pi));
else
tmp = Float64(180.0 * Float64(atan(Float64(Float64(Float64(C - A) - hypot(B, Float64(A - C))) / B)) / pi));
end
return tmp
end
function tmp = code(A, B, C)
tmp = 180.0 * (atan(((1.0 / B) * ((C - A) - sqrt((((A - C) ^ 2.0) + (B ^ 2.0)))))) / pi);
end
↓
function tmp_2 = code(A, B, C)
tmp = 0.0;
if (A <= -1.2e+64)
tmp = 180.0 * (atan(((0.5 * B) / A)) / pi);
else
tmp = 180.0 * (atan((((C - A) - hypot(B, (A - C))) / B)) / pi);
end
tmp_2 = tmp;
end
The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.
Herbie found 14 alternatives:
Alternative
Accuracy
Speedup
Accuracy vs Speed
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.
herbie shell --seed 2023272
(FPCore (A B C)
:name "ABCF->ab-angle angle"
:precision binary64
(* 180.0 (/ (atan (* (/ 1.0 B) (- (- C A) (sqrt (+ (pow (- A C) 2.0) (pow B 2.0)))))) PI)))