
(FPCore (v H) :precision binary64 (atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))
double code(double v, double H) {
return atan((v / sqrt(((v * v) - ((2.0 * 9.8) * H)))));
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
code = atan((v / sqrt(((v * v) - ((2.0d0 * 9.8d0) * h)))))
end function
public static double code(double v, double H) {
return Math.atan((v / Math.sqrt(((v * v) - ((2.0 * 9.8) * H)))));
}
def code(v, H): return math.atan((v / math.sqrt(((v * v) - ((2.0 * 9.8) * H)))))
function code(v, H) return atan(Float64(v / sqrt(Float64(Float64(v * v) - Float64(Float64(2.0 * 9.8) * H))))) end
function tmp = code(v, H) tmp = atan((v / sqrt(((v * v) - ((2.0 * 9.8) * H))))); end
code[v_, H_] := N[ArcTan[N[(v / N[Sqrt[N[(N[(v * v), $MachinePrecision] - N[(N[(2.0 * 9.8), $MachinePrecision] * H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (v H) :precision binary64 (atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))
double code(double v, double H) {
return atan((v / sqrt(((v * v) - ((2.0 * 9.8) * H)))));
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
code = atan((v / sqrt(((v * v) - ((2.0d0 * 9.8d0) * h)))))
end function
public static double code(double v, double H) {
return Math.atan((v / Math.sqrt(((v * v) - ((2.0 * 9.8) * H)))));
}
def code(v, H): return math.atan((v / math.sqrt(((v * v) - ((2.0 * 9.8) * H)))))
function code(v, H) return atan(Float64(v / sqrt(Float64(Float64(v * v) - Float64(Float64(2.0 * 9.8) * H))))) end
function tmp = code(v, H) tmp = atan((v / sqrt(((v * v) - ((2.0 * 9.8) * H))))); end
code[v_, H_] := N[ArcTan[N[(v / N[Sqrt[N[(N[(v * v), $MachinePrecision] - N[(N[(2.0 * 9.8), $MachinePrecision] * H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right)
\end{array}
(FPCore (v H)
:precision binary64
(if (<= v -1e+154)
(atan -1.0)
(if (<= v 2e+108)
(atan (/ v (sqrt (- (* v v) (* 19.6 H)))))
(atan (/ v (* v (+ 1.0 (* -9.8 (/ H (pow v 2.0))))))))))
double code(double v, double H) {
double tmp;
if (v <= -1e+154) {
tmp = atan(-1.0);
} else if (v <= 2e+108) {
tmp = atan((v / sqrt(((v * v) - (19.6 * H)))));
} else {
tmp = atan((v / (v * (1.0 + (-9.8 * (H / pow(v, 2.0)))))));
}
return tmp;
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
real(8) :: tmp
if (v <= (-1d+154)) then
tmp = atan((-1.0d0))
else if (v <= 2d+108) then
tmp = atan((v / sqrt(((v * v) - (19.6d0 * h)))))
else
tmp = atan((v / (v * (1.0d0 + ((-9.8d0) * (h / (v ** 2.0d0)))))))
end if
code = tmp
end function
public static double code(double v, double H) {
double tmp;
if (v <= -1e+154) {
tmp = Math.atan(-1.0);
} else if (v <= 2e+108) {
tmp = Math.atan((v / Math.sqrt(((v * v) - (19.6 * H)))));
} else {
tmp = Math.atan((v / (v * (1.0 + (-9.8 * (H / Math.pow(v, 2.0)))))));
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -1e+154: tmp = math.atan(-1.0) elif v <= 2e+108: tmp = math.atan((v / math.sqrt(((v * v) - (19.6 * H))))) else: tmp = math.atan((v / (v * (1.0 + (-9.8 * (H / math.pow(v, 2.0))))))) return tmp
function code(v, H) tmp = 0.0 if (v <= -1e+154) tmp = atan(-1.0); elseif (v <= 2e+108) tmp = atan(Float64(v / sqrt(Float64(Float64(v * v) - Float64(19.6 * H))))); else tmp = atan(Float64(v / Float64(v * Float64(1.0 + Float64(-9.8 * Float64(H / (v ^ 2.0))))))); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -1e+154) tmp = atan(-1.0); elseif (v <= 2e+108) tmp = atan((v / sqrt(((v * v) - (19.6 * H))))); else tmp = atan((v / (v * (1.0 + (-9.8 * (H / (v ^ 2.0))))))); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -1e+154], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 2e+108], N[ArcTan[N[(v / N[Sqrt[N[(N[(v * v), $MachinePrecision] - N[(19.6 * H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[N[(v / N[(v * N[(1.0 + N[(-9.8 * N[(H / N[Power[v, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -1 \cdot 10^{+154}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 2 \cdot 10^{+108}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - 19.6 \cdot H}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{v \cdot \left(1 + -9.8 \cdot \frac{H}{{v}^{2}}\right)}\right)\\
\end{array}
\end{array}
if v < -1.00000000000000004e154Initial program 3.1%
Taylor expanded in v around -inf 100.0%
if -1.00000000000000004e154 < v < 2.0000000000000001e108Initial program 99.7%
Taylor expanded in H around 0 99.7%
if 2.0000000000000001e108 < v Initial program 20.7%
Taylor expanded in v around inf 100.0%
(FPCore (v H) :precision binary64 (if (<= v -1e+154) (atan -1.0) (if (<= v 5e+141) (atan (/ v (sqrt (- (* v v) (* 19.6 H))))) (atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -1e+154) {
tmp = atan(-1.0);
} else if (v <= 5e+141) {
tmp = atan((v / sqrt(((v * v) - (19.6 * H)))));
} else {
tmp = atan(1.0);
}
return tmp;
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
real(8) :: tmp
if (v <= (-1d+154)) then
tmp = atan((-1.0d0))
else if (v <= 5d+141) then
tmp = atan((v / sqrt(((v * v) - (19.6d0 * h)))))
else
tmp = atan(1.0d0)
end if
code = tmp
end function
public static double code(double v, double H) {
double tmp;
if (v <= -1e+154) {
tmp = Math.atan(-1.0);
} else if (v <= 5e+141) {
tmp = Math.atan((v / Math.sqrt(((v * v) - (19.6 * H)))));
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -1e+154: tmp = math.atan(-1.0) elif v <= 5e+141: tmp = math.atan((v / math.sqrt(((v * v) - (19.6 * H))))) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -1e+154) tmp = atan(-1.0); elseif (v <= 5e+141) tmp = atan(Float64(v / sqrt(Float64(Float64(v * v) - Float64(19.6 * H))))); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -1e+154) tmp = atan(-1.0); elseif (v <= 5e+141) tmp = atan((v / sqrt(((v * v) - (19.6 * H))))); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -1e+154], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 5e+141], N[ArcTan[N[(v / N[Sqrt[N[(N[(v * v), $MachinePrecision] - N[(19.6 * H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -1 \cdot 10^{+154}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 5 \cdot 10^{+141}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - 19.6 \cdot H}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -1.00000000000000004e154Initial program 3.1%
Taylor expanded in v around -inf 100.0%
if -1.00000000000000004e154 < v < 5.00000000000000025e141Initial program 99.7%
Taylor expanded in H around 0 99.7%
if 5.00000000000000025e141 < v Initial program 9.8%
Taylor expanded in v around inf 100.0%
(FPCore (v H)
:precision binary64
(if (<= v -1.25e-54)
(atan -1.0)
(if (<= v 4.8e-46)
(atan (* v (sqrt (/ -0.05102040816326531 H))))
(atan (/ v (+ v (* -9.8 (/ H v))))))))
double code(double v, double H) {
double tmp;
if (v <= -1.25e-54) {
tmp = atan(-1.0);
} else if (v <= 4.8e-46) {
tmp = atan((v * sqrt((-0.05102040816326531 / H))));
} else {
tmp = atan((v / (v + (-9.8 * (H / v)))));
}
return tmp;
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
real(8) :: tmp
if (v <= (-1.25d-54)) then
tmp = atan((-1.0d0))
else if (v <= 4.8d-46) then
tmp = atan((v * sqrt(((-0.05102040816326531d0) / h))))
else
tmp = atan((v / (v + ((-9.8d0) * (h / v)))))
end if
code = tmp
end function
public static double code(double v, double H) {
double tmp;
if (v <= -1.25e-54) {
tmp = Math.atan(-1.0);
} else if (v <= 4.8e-46) {
tmp = Math.atan((v * Math.sqrt((-0.05102040816326531 / H))));
} else {
tmp = Math.atan((v / (v + (-9.8 * (H / v)))));
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -1.25e-54: tmp = math.atan(-1.0) elif v <= 4.8e-46: tmp = math.atan((v * math.sqrt((-0.05102040816326531 / H)))) else: tmp = math.atan((v / (v + (-9.8 * (H / v))))) return tmp
function code(v, H) tmp = 0.0 if (v <= -1.25e-54) tmp = atan(-1.0); elseif (v <= 4.8e-46) tmp = atan(Float64(v * sqrt(Float64(-0.05102040816326531 / H)))); else tmp = atan(Float64(v / Float64(v + Float64(-9.8 * Float64(H / v))))); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -1.25e-54) tmp = atan(-1.0); elseif (v <= 4.8e-46) tmp = atan((v * sqrt((-0.05102040816326531 / H)))); else tmp = atan((v / (v + (-9.8 * (H / v))))); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -1.25e-54], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 4.8e-46], N[ArcTan[N[(v * N[Sqrt[N[(-0.05102040816326531 / H), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[N[(v / N[(v + N[(-9.8 * N[(H / v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -1.25 \cdot 10^{-54}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 4.8 \cdot 10^{-46}:\\
\;\;\;\;\tan^{-1} \left(v \cdot \sqrt{\frac{-0.05102040816326531}{H}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{v + -9.8 \cdot \frac{H}{v}}\right)\\
\end{array}
\end{array}
if v < -1.25000000000000004e-54Initial program 49.2%
Taylor expanded in v around -inf 88.6%
if -1.25000000000000004e-54 < v < 4.80000000000000027e-46Initial program 99.6%
Taylor expanded in v around 0 99.6%
Taylor expanded in v around 0 89.9%
if 4.80000000000000027e-46 < v Initial program 46.5%
Taylor expanded in H around 0 94.4%
(FPCore (v H) :precision binary64 (if (<= v -2.3e-159) (atan -1.0) (atan (/ v (+ v (* -9.8 (/ H v)))))))
double code(double v, double H) {
double tmp;
if (v <= -2.3e-159) {
tmp = atan(-1.0);
} else {
tmp = atan((v / (v + (-9.8 * (H / v)))));
}
return tmp;
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
real(8) :: tmp
if (v <= (-2.3d-159)) then
tmp = atan((-1.0d0))
else
tmp = atan((v / (v + ((-9.8d0) * (h / v)))))
end if
code = tmp
end function
public static double code(double v, double H) {
double tmp;
if (v <= -2.3e-159) {
tmp = Math.atan(-1.0);
} else {
tmp = Math.atan((v / (v + (-9.8 * (H / v)))));
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -2.3e-159: tmp = math.atan(-1.0) else: tmp = math.atan((v / (v + (-9.8 * (H / v))))) return tmp
function code(v, H) tmp = 0.0 if (v <= -2.3e-159) tmp = atan(-1.0); else tmp = atan(Float64(v / Float64(v + Float64(-9.8 * Float64(H / v))))); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -2.3e-159) tmp = atan(-1.0); else tmp = atan((v / (v + (-9.8 * (H / v))))); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -2.3e-159], N[ArcTan[-1.0], $MachinePrecision], N[ArcTan[N[(v / N[(v + N[(-9.8 * N[(H / v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -2.3 \cdot 10^{-159}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{v + -9.8 \cdot \frac{H}{v}}\right)\\
\end{array}
\end{array}
if v < -2.29999999999999978e-159Initial program 59.8%
Taylor expanded in v around -inf 73.9%
if -2.29999999999999978e-159 < v Initial program 65.4%
Taylor expanded in H around 0 74.7%
(FPCore (v H) :precision binary64 (if (<= v -1.3e-302) (atan -1.0) (atan 1.0)))
double code(double v, double H) {
double tmp;
if (v <= -1.3e-302) {
tmp = atan(-1.0);
} else {
tmp = atan(1.0);
}
return tmp;
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
real(8) :: tmp
if (v <= (-1.3d-302)) then
tmp = atan((-1.0d0))
else
tmp = atan(1.0d0)
end if
code = tmp
end function
public static double code(double v, double H) {
double tmp;
if (v <= -1.3e-302) {
tmp = Math.atan(-1.0);
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -1.3e-302: tmp = math.atan(-1.0) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -1.3e-302) tmp = atan(-1.0); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -1.3e-302) tmp = atan(-1.0); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -1.3e-302], N[ArcTan[-1.0], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -1.3 \cdot 10^{-302}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -1.30000000000000006e-302Initial program 65.9%
Taylor expanded in v around -inf 63.1%
if -1.30000000000000006e-302 < v Initial program 60.5%
Taylor expanded in v around inf 72.7%
(FPCore (v H) :precision binary64 (atan -1.0))
double code(double v, double H) {
return atan(-1.0);
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
code = atan((-1.0d0))
end function
public static double code(double v, double H) {
return Math.atan(-1.0);
}
def code(v, H): return math.atan(-1.0)
function code(v, H) return atan(-1.0) end
function tmp = code(v, H) tmp = atan(-1.0); end
code[v_, H_] := N[ArcTan[-1.0], $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1} -1
\end{array}
Initial program 63.1%
Taylor expanded in v around -inf 31.3%
herbie shell --seed 2024170
(FPCore (v H)
:name "Optimal throwing angle"
:precision binary64
(atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))