\[\left(\left(-1.6 \leq lat1 \land lat1 \leq 1.6\right) \land \left(-1.6 \leq lat2 \land lat2 \leq 1.6\right)\right) \land \left(-6.4 \leq dlon \land dlon \leq 6.4\right)\]
\[2 \cdot \sin^{-1} \left(\sqrt{{\sin \left(\frac{lat1 - lat2}{2}\right)}^{2} + \left(\cos lat1 \cdot \cos lat2\right) \cdot {\sin \left(\frac{dlon}{2}\right)}^{2}}\right)
\]
↓
\[2 \cdot \sin^{-1} \left(\mathsf{hypot}\left(\sqrt{\cos lat2} \cdot \sin \left(dlon \cdot 0.5\right), \sin \left(0.5 \cdot \left(lat1 - lat2\right)\right)\right)\right)
\]
(FPCore (lat1 lat2 dlon)
:precision binary64
(*
2.0
(asin
(sqrt
(+
(pow (sin (/ (- lat1 lat2) 2.0)) 2.0)
(* (* (cos lat1) (cos lat2)) (pow (sin (/ dlon 2.0)) 2.0)))))))
↓
(FPCore (lat1 lat2 dlon)
:precision binary64
(*
2.0
(asin
(hypot
(* (sqrt (cos lat2)) (sin (* dlon 0.5)))
(sin (* 0.5 (- lat1 lat2)))))))
double code(double lat1, double lat2, double dlon) {
return 2.0 * asin(sqrt((pow(sin(((lat1 - lat2) / 2.0)), 2.0) + ((cos(lat1) * cos(lat2)) * pow(sin((dlon / 2.0)), 2.0)))));
}
↓
double code(double lat1, double lat2, double dlon) {
return 2.0 * asin(hypot((sqrt(cos(lat2)) * sin((dlon * 0.5))), sin((0.5 * (lat1 - lat2)))));
}
public static double code(double lat1, double lat2, double dlon) {
return 2.0 * Math.asin(Math.sqrt((Math.pow(Math.sin(((lat1 - lat2) / 2.0)), 2.0) + ((Math.cos(lat1) * Math.cos(lat2)) * Math.pow(Math.sin((dlon / 2.0)), 2.0)))));
}
↓
public static double code(double lat1, double lat2, double dlon) {
return 2.0 * Math.asin(Math.hypot((Math.sqrt(Math.cos(lat2)) * Math.sin((dlon * 0.5))), Math.sin((0.5 * (lat1 - lat2)))));
}
def code(lat1, lat2, dlon):
return 2.0 * math.asin(math.sqrt((math.pow(math.sin(((lat1 - lat2) / 2.0)), 2.0) + ((math.cos(lat1) * math.cos(lat2)) * math.pow(math.sin((dlon / 2.0)), 2.0)))))
↓
def code(lat1, lat2, dlon):
return 2.0 * math.asin(math.hypot((math.sqrt(math.cos(lat2)) * math.sin((dlon * 0.5))), math.sin((0.5 * (lat1 - lat2)))))
function code(lat1, lat2, dlon)
return Float64(2.0 * asin(sqrt(Float64((sin(Float64(Float64(lat1 - lat2) / 2.0)) ^ 2.0) + Float64(Float64(cos(lat1) * cos(lat2)) * (sin(Float64(dlon / 2.0)) ^ 2.0))))))
end
↓
function code(lat1, lat2, dlon)
return Float64(2.0 * asin(hypot(Float64(sqrt(cos(lat2)) * sin(Float64(dlon * 0.5))), sin(Float64(0.5 * Float64(lat1 - lat2))))))
end
function tmp = code(lat1, lat2, dlon)
tmp = 2.0 * asin(sqrt(((sin(((lat1 - lat2) / 2.0)) ^ 2.0) + ((cos(lat1) * cos(lat2)) * (sin((dlon / 2.0)) ^ 2.0)))));
end
↓
function tmp = code(lat1, lat2, dlon)
tmp = 2.0 * asin(hypot((sqrt(cos(lat2)) * sin((dlon * 0.5))), sin((0.5 * (lat1 - lat2)))));
end
code[lat1_, lat2_, dlon_] := N[(2.0 * N[ArcSin[N[Sqrt[N[(N[Power[N[Sin[N[(N[(lat1 - lat2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(N[Cos[lat1], $MachinePrecision] * N[Cos[lat2], $MachinePrecision]), $MachinePrecision] * N[Power[N[Sin[N[(dlon / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
↓
code[lat1_, lat2_, dlon_] := N[(2.0 * N[ArcSin[N[Sqrt[N[(N[Sqrt[N[Cos[lat2], $MachinePrecision]], $MachinePrecision] * N[Sin[N[(dlon * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] ^ 2 + N[Sin[N[(0.5 * N[(lat1 - lat2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
2 \cdot \sin^{-1} \left(\sqrt{{\sin \left(\frac{lat1 - lat2}{2}\right)}^{2} + \left(\cos lat1 \cdot \cos lat2\right) \cdot {\sin \left(\frac{dlon}{2}\right)}^{2}}\right)
↓
2 \cdot \sin^{-1} \left(\mathsf{hypot}\left(\sqrt{\cos lat2} \cdot \sin \left(dlon \cdot 0.5\right), \sin \left(0.5 \cdot \left(lat1 - lat2\right)\right)\right)\right)
Alternatives
Alternative 1 |
---|
Error | 15.5 |
---|
Cost | 39300 |
---|
\[\begin{array}{l}
\mathbf{if}\;lat1 \leq -7.4 \cdot 10^{-151}:\\
\;\;\;\;2 \cdot \sin^{-1} \left(\sqrt{\mathsf{fma}\left(0.25, \left(dlon \cdot dlon\right) \cdot \cos lat1, {\sin \left(0.5 \cdot lat1\right)}^{2}\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \sin^{-1} \left(\mathsf{hypot}\left(\sqrt{\cos lat2} \cdot \sin \left(dlon \cdot 0.5\right), \sin \left(lat2 \cdot -0.5\right)\right)\right)\\
\end{array}
\]
Alternative 2 |
---|
Error | 15.2 |
---|
Cost | 39172 |
---|
\[\begin{array}{l}
\mathbf{if}\;lat1 \leq -9 \cdot 10^{-152}:\\
\;\;\;\;2 \cdot \sin^{-1} \left(\sqrt{{\sin \left(0.5 \cdot \left(lat1 - lat2\right)\right)}^{2}}\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \sin^{-1} \left(\mathsf{hypot}\left(\sqrt{\cos lat2} \cdot \sin \left(dlon \cdot 0.5\right), \sin \left(lat2 \cdot -0.5\right)\right)\right)\\
\end{array}
\]
Alternative 3 |
---|
Error | 14.4 |
---|
Cost | 33426 |
---|
\[\begin{array}{l}
\mathbf{if}\;dlon \leq -2.1 \cdot 10^{-101} \lor \neg \left(dlon \leq -4.4 \cdot 10^{-118}\right) \land \left(dlon \leq -1.4 \cdot 10^{-139} \lor \neg \left(dlon \leq 2.3 \cdot 10^{-132}\right)\right):\\
\;\;\;\;2 \cdot \sin^{-1} \left(\sqrt{{\sin \left(lat2 \cdot -0.5\right)}^{2} + \cos lat2 \cdot \left(dlon \cdot \left(dlon \cdot 0.25\right)\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \sin^{-1} \left(\sqrt{{\sin \left(0.5 \cdot \left(lat1 - lat2\right)\right)}^{2}}\right)\\
\end{array}
\]
Alternative 4 |
---|
Error | 17.9 |
---|
Cost | 26376 |
---|
\[\begin{array}{l}
t_0 := \sin \left(dlon \cdot 0.5\right)\\
\mathbf{if}\;dlon \leq -1.45 \cdot 10^{-101}:\\
\;\;\;\;2 \cdot \sin^{-1} \left(\sqrt{{t_0}^{2}}\right)\\
\mathbf{elif}\;dlon \leq 1.2 \cdot 10^{-132}:\\
\;\;\;\;2 \cdot \sin^{-1} \left(\sqrt{{\sin \left(0.5 \cdot \left(lat1 - lat2\right)\right)}^{2}}\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \sin^{-1} t_0\\
\end{array}
\]
Alternative 5 |
---|
Error | 44.0 |
---|
Cost | 26116 |
---|
\[\begin{array}{l}
\mathbf{if}\;lat2 \leq 4.5 \cdot 10^{-139}:\\
\;\;\;\;2 \cdot \sin^{-1} \sin \left(dlon \cdot 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \sin^{-1} \left(\sqrt{{\sin \left(lat2 \cdot -0.5\right)}^{2}}\right)\\
\end{array}
\]
Alternative 6 |
---|
Error | 37.2 |
---|
Cost | 26116 |
---|
\[\begin{array}{l}
\mathbf{if}\;lat2 \leq 5.9 \cdot 10^{-124}:\\
\;\;\;\;2 \cdot \sin^{-1} \left(\sqrt{{\sin \left(dlon \cdot 0.5\right)}^{2}}\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \sin^{-1} \left(\sqrt{{\sin \left(lat2 \cdot -0.5\right)}^{2}}\right)\\
\end{array}
\]
Alternative 7 |
---|
Error | 51.7 |
---|
Cost | 13120 |
---|
\[2 \cdot \sin^{-1} \sin \left(lat2 \cdot -0.5\right)
\]
Alternative 8 |
---|
Error | 51.4 |
---|
Cost | 13120 |
---|
\[2 \cdot \sin^{-1} \sin \left(dlon \cdot 0.5\right)
\]