Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Write the same code in Java as shown below in AWK.
BEGIN { distance(36.12,-86.67,33.94,-118.40) exit(0) } function distance(lat1,lon1,lat2,lon2, a,c,dlat,dlon) { dlat = radians(lat2-lat1) dlon = radians(lon2-lon1) lat1 = radians(lat1) lat2 = radians(lat2) a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2 c = 2 * atan2(sqr...
public class Haversine { public static final double R = 6372.8; public static double haversine(double lat1, double lon1, double lat2, double lon2) { lat1 = Math.toRadians(lat1); lat2 = Math.toRadians(lat2); double dLat = lat2 - lat1; double dLon = Math.toRadians(lon2 - lon1); ...
Generate a Java translation of this AWK snippet without changing its computational steps.
BEGIN { distance(36.12,-86.67,33.94,-118.40) exit(0) } function distance(lat1,lon1,lat2,lon2, a,c,dlat,dlon) { dlat = radians(lat2-lat1) dlon = radians(lon2-lon1) lat1 = radians(lat1) lat2 = radians(lat2) a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2 c = 2 * atan2(sqr...
public class Haversine { public static final double R = 6372.8; public static double haversine(double lat1, double lon1, double lat2, double lon2) { lat1 = Math.toRadians(lat1); lat2 = Math.toRadians(lat2); double dLat = lat2 - lat1; double dLon = Math.toRadians(lon2 - lon1); ...
Rewrite this program in Python while keeping its functionality equivalent to the AWK version.
BEGIN { distance(36.12,-86.67,33.94,-118.40) exit(0) } function distance(lat1,lon1,lat2,lon2, a,c,dlat,dlon) { dlat = radians(lat2-lat1) dlon = radians(lon2-lon1) lat1 = radians(lat1) lat2 = radians(lat2) a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2 c = 2 * atan2(sqr...
from math import radians, sin, cos, sqrt, asin def haversine(lat1, lon1, lat2, lon2): R = 6372.8 dLat = radians(lat2 - lat1) dLon = radians(lon2 - lon1) lat1 = radians(lat1) lat2 = radians(lat2) a = sin(dLat / 2)**2 + cos(lat1) * cos(lat2) * sin(dLon / 2)**2 c = 2 * asin(sqrt(a)) ...
Write the same algorithm in Python as shown in this AWK implementation.
BEGIN { distance(36.12,-86.67,33.94,-118.40) exit(0) } function distance(lat1,lon1,lat2,lon2, a,c,dlat,dlon) { dlat = radians(lat2-lat1) dlon = radians(lon2-lon1) lat1 = radians(lat1) lat2 = radians(lat2) a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2 c = 2 * atan2(sqr...
from math import radians, sin, cos, sqrt, asin def haversine(lat1, lon1, lat2, lon2): R = 6372.8 dLat = radians(lat2 - lat1) dLon = radians(lon2 - lon1) lat1 = radians(lat1) lat2 = radians(lat2) a = sin(dLat / 2)**2 + cos(lat1) * cos(lat2) * sin(dLon / 2)**2 c = 2 * asin(sqrt(a)) ...
Transform the following AWK implementation into VB, maintaining the same output and logic.
BEGIN { distance(36.12,-86.67,33.94,-118.40) exit(0) } function distance(lat1,lon1,lat2,lon2, a,c,dlat,dlon) { dlat = radians(lat2-lat1) dlon = radians(lon2-lon1) lat1 = radians(lat1) lat2 = radians(lat2) a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2 c = 2 * atan2(sqr...
Const MER = 6371 Public DEG_TO_RAD As Double Function haversine(lat1 As Double, long1 As Double, lat2 As Double, long2 As Double) As Double lat1 = lat1 * DEG_TO_RAD lat2 = lat2 * DEG_TO_RAD long1 = long1 * DEG_TO_RAD long2 = long2 * DEG_TO_RAD haversine = MER * WorksheetFunction.Acos(Sin(...
Produce a functionally identical VB code for the snippet given in AWK.
BEGIN { distance(36.12,-86.67,33.94,-118.40) exit(0) } function distance(lat1,lon1,lat2,lon2, a,c,dlat,dlon) { dlat = radians(lat2-lat1) dlon = radians(lon2-lon1) lat1 = radians(lat1) lat2 = radians(lat2) a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2 c = 2 * atan2(sqr...
Const MER = 6371 Public DEG_TO_RAD As Double Function haversine(lat1 As Double, long1 As Double, lat2 As Double, long2 As Double) As Double lat1 = lat1 * DEG_TO_RAD lat2 = lat2 * DEG_TO_RAD long1 = long1 * DEG_TO_RAD long2 = long2 * DEG_TO_RAD haversine = MER * WorksheetFunction.Acos(Sin(...
Change the programming language of this snippet from AWK to Go without modifying what it does.
BEGIN { distance(36.12,-86.67,33.94,-118.40) exit(0) } function distance(lat1,lon1,lat2,lon2, a,c,dlat,dlon) { dlat = radians(lat2-lat1) dlon = radians(lon2-lon1) lat1 = radians(lat1) lat2 = radians(lat2) a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2 c = 2 * atan2(sqr...
package main import ( "fmt" "math" ) func haversine(θ float64) float64 { return .5 * (1 - math.Cos(θ)) } type pos struct { φ float64 ψ float64 } func degPos(lat, lon float64) pos { return pos{lat * math.Pi / 180, lon * math.Pi / 180} } const rEarth = 6372.8 func hsDist(p1, p2 pos) float...
Rewrite the snippet below in Go so it works the same as the original AWK code.
BEGIN { distance(36.12,-86.67,33.94,-118.40) exit(0) } function distance(lat1,lon1,lat2,lon2, a,c,dlat,dlon) { dlat = radians(lat2-lat1) dlon = radians(lon2-lon1) lat1 = radians(lat1) lat2 = radians(lat2) a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2 c = 2 * atan2(sqr...
package main import ( "fmt" "math" ) func haversine(θ float64) float64 { return .5 * (1 - math.Cos(θ)) } type pos struct { φ float64 ψ float64 } func degPos(lat, lon float64) pos { return pos{lat * math.Pi / 180, lon * math.Pi / 180} } const rEarth = 6372.8 func hsDist(p1, p2 pos) float...
Produce a functionally identical C code for the snippet given in BBC_Basic.
PRINT "Distance = " ; FNhaversine(36.12, -86.67, 33.94, -118.4) " km" END DEF FNhaversine(n1, e1, n2, e2) LOCAL d() : DIM d(2) d() = COSRAD(e1-e2) * COSRAD(n1) - COSRAD(n2), \ \ SINRAD(e1-e2) * COSRAD(n1), \ \ SINRAD(n1) - SINRAD(n2) = ASN(MOD(d()) / 2) * 6...
#include <stdio.h> #include <stdlib.h> #include <math.h> #define R 6371 #define TO_RAD (3.1415926536 / 180) double dist(double th1, double ph1, double th2, double ph2) { double dx, dy, dz; ph1 -= ph2; ph1 *= TO_RAD, th1 *= TO_RAD, th2 *= TO_RAD; dz = sin(th1) - sin(th2); dx = cos(ph1) * cos(th1) - cos(th2); dy ...
Can you help me rewrite this code in C instead of BBC_Basic, keeping it the same logically?
PRINT "Distance = " ; FNhaversine(36.12, -86.67, 33.94, -118.4) " km" END DEF FNhaversine(n1, e1, n2, e2) LOCAL d() : DIM d(2) d() = COSRAD(e1-e2) * COSRAD(n1) - COSRAD(n2), \ \ SINRAD(e1-e2) * COSRAD(n1), \ \ SINRAD(n1) - SINRAD(n2) = ASN(MOD(d()) / 2) * 6...
#include <stdio.h> #include <stdlib.h> #include <math.h> #define R 6371 #define TO_RAD (3.1415926536 / 180) double dist(double th1, double ph1, double th2, double ph2) { double dx, dy, dz; ph1 -= ph2; ph1 *= TO_RAD, th1 *= TO_RAD, th2 *= TO_RAD; dz = sin(th1) - sin(th2); dx = cos(ph1) * cos(th1) - cos(th2); dy ...
Rewrite the snippet below in C# so it works the same as the original BBC_Basic code.
PRINT "Distance = " ; FNhaversine(36.12, -86.67, 33.94, -118.4) " km" END DEF FNhaversine(n1, e1, n2, e2) LOCAL d() : DIM d(2) d() = COSRAD(e1-e2) * COSRAD(n1) - COSRAD(n2), \ \ SINRAD(e1-e2) * COSRAD(n1), \ \ SINRAD(n1) - SINRAD(n2) = ASN(MOD(d()) / 2) * 6...
public static class Haversine { public static double calculate(double lat1, double lon1, double lat2, double lon2) { var R = 6372.8; var dLat = toRadians(lat2 - lat1); var dLon = toRadians(lon2 - lon1); lat1 = toRadians(lat1); lat2 = toRadians(lat2); var a = Math.Sin(dLat / 2) * Math.Sin(...
Write a version of this BBC_Basic function in C# with identical behavior.
PRINT "Distance = " ; FNhaversine(36.12, -86.67, 33.94, -118.4) " km" END DEF FNhaversine(n1, e1, n2, e2) LOCAL d() : DIM d(2) d() = COSRAD(e1-e2) * COSRAD(n1) - COSRAD(n2), \ \ SINRAD(e1-e2) * COSRAD(n1), \ \ SINRAD(n1) - SINRAD(n2) = ASN(MOD(d()) / 2) * 6...
public static class Haversine { public static double calculate(double lat1, double lon1, double lat2, double lon2) { var R = 6372.8; var dLat = toRadians(lat2 - lat1); var dLon = toRadians(lon2 - lon1); lat1 = toRadians(lat1); lat2 = toRadians(lat2); var a = Math.Sin(dLat / 2) * Math.Sin(...
Rewrite this program in C++ while keeping its functionality equivalent to the BBC_Basic version.
PRINT "Distance = " ; FNhaversine(36.12, -86.67, 33.94, -118.4) " km" END DEF FNhaversine(n1, e1, n2, e2) LOCAL d() : DIM d(2) d() = COSRAD(e1-e2) * COSRAD(n1) - COSRAD(n2), \ \ SINRAD(e1-e2) * COSRAD(n1), \ \ SINRAD(n1) - SINRAD(n2) = ASN(MOD(d()) / 2) * 6...
#define _USE_MATH_DEFINES #include <math.h> #include <iostream> const static double EarthRadiusKm = 6372.8; inline double DegreeToRadian(double angle) { return M_PI * angle / 180.0; } class Coordinate { public: Coordinate(double latitude ,double longitude):myLatitude(latitude), myLongitude(longitude) {} double...
Write a version of this BBC_Basic function in C++ with identical behavior.
PRINT "Distance = " ; FNhaversine(36.12, -86.67, 33.94, -118.4) " km" END DEF FNhaversine(n1, e1, n2, e2) LOCAL d() : DIM d(2) d() = COSRAD(e1-e2) * COSRAD(n1) - COSRAD(n2), \ \ SINRAD(e1-e2) * COSRAD(n1), \ \ SINRAD(n1) - SINRAD(n2) = ASN(MOD(d()) / 2) * 6...
#define _USE_MATH_DEFINES #include <math.h> #include <iostream> const static double EarthRadiusKm = 6372.8; inline double DegreeToRadian(double angle) { return M_PI * angle / 180.0; } class Coordinate { public: Coordinate(double latitude ,double longitude):myLatitude(latitude), myLongitude(longitude) {} double...
Change the following BBC_Basic code into Java without altering its purpose.
PRINT "Distance = " ; FNhaversine(36.12, -86.67, 33.94, -118.4) " km" END DEF FNhaversine(n1, e1, n2, e2) LOCAL d() : DIM d(2) d() = COSRAD(e1-e2) * COSRAD(n1) - COSRAD(n2), \ \ SINRAD(e1-e2) * COSRAD(n1), \ \ SINRAD(n1) - SINRAD(n2) = ASN(MOD(d()) / 2) * 6...
public class Haversine { public static final double R = 6372.8; public static double haversine(double lat1, double lon1, double lat2, double lon2) { lat1 = Math.toRadians(lat1); lat2 = Math.toRadians(lat2); double dLat = lat2 - lat1; double dLon = Math.toRadians(lon2 - lon1); ...
Convert this BBC_Basic block to Java, preserving its control flow and logic.
PRINT "Distance = " ; FNhaversine(36.12, -86.67, 33.94, -118.4) " km" END DEF FNhaversine(n1, e1, n2, e2) LOCAL d() : DIM d(2) d() = COSRAD(e1-e2) * COSRAD(n1) - COSRAD(n2), \ \ SINRAD(e1-e2) * COSRAD(n1), \ \ SINRAD(n1) - SINRAD(n2) = ASN(MOD(d()) / 2) * 6...
public class Haversine { public static final double R = 6372.8; public static double haversine(double lat1, double lon1, double lat2, double lon2) { lat1 = Math.toRadians(lat1); lat2 = Math.toRadians(lat2); double dLat = lat2 - lat1; double dLon = Math.toRadians(lon2 - lon1); ...
Convert this BBC_Basic snippet to Python and keep its semantics consistent.
PRINT "Distance = " ; FNhaversine(36.12, -86.67, 33.94, -118.4) " km" END DEF FNhaversine(n1, e1, n2, e2) LOCAL d() : DIM d(2) d() = COSRAD(e1-e2) * COSRAD(n1) - COSRAD(n2), \ \ SINRAD(e1-e2) * COSRAD(n1), \ \ SINRAD(n1) - SINRAD(n2) = ASN(MOD(d()) / 2) * 6...
from math import radians, sin, cos, sqrt, asin def haversine(lat1, lon1, lat2, lon2): R = 6372.8 dLat = radians(lat2 - lat1) dLon = radians(lon2 - lon1) lat1 = radians(lat1) lat2 = radians(lat2) a = sin(dLat / 2)**2 + cos(lat1) * cos(lat2) * sin(dLon / 2)**2 c = 2 * asin(sqrt(a)) ...
Convert this BBC_Basic snippet to Python and keep its semantics consistent.
PRINT "Distance = " ; FNhaversine(36.12, -86.67, 33.94, -118.4) " km" END DEF FNhaversine(n1, e1, n2, e2) LOCAL d() : DIM d(2) d() = COSRAD(e1-e2) * COSRAD(n1) - COSRAD(n2), \ \ SINRAD(e1-e2) * COSRAD(n1), \ \ SINRAD(n1) - SINRAD(n2) = ASN(MOD(d()) / 2) * 6...
from math import radians, sin, cos, sqrt, asin def haversine(lat1, lon1, lat2, lon2): R = 6372.8 dLat = radians(lat2 - lat1) dLon = radians(lon2 - lon1) lat1 = radians(lat1) lat2 = radians(lat2) a = sin(dLat / 2)**2 + cos(lat1) * cos(lat2) * sin(dLon / 2)**2 c = 2 * asin(sqrt(a)) ...
Keep all operations the same but rewrite the snippet in VB.
PRINT "Distance = " ; FNhaversine(36.12, -86.67, 33.94, -118.4) " km" END DEF FNhaversine(n1, e1, n2, e2) LOCAL d() : DIM d(2) d() = COSRAD(e1-e2) * COSRAD(n1) - COSRAD(n2), \ \ SINRAD(e1-e2) * COSRAD(n1), \ \ SINRAD(n1) - SINRAD(n2) = ASN(MOD(d()) / 2) * 6...
Const MER = 6371 Public DEG_TO_RAD As Double Function haversine(lat1 As Double, long1 As Double, lat2 As Double, long2 As Double) As Double lat1 = lat1 * DEG_TO_RAD lat2 = lat2 * DEG_TO_RAD long1 = long1 * DEG_TO_RAD long2 = long2 * DEG_TO_RAD haversine = MER * WorksheetFunction.Acos(Sin(...
Produce a functionally identical VB code for the snippet given in BBC_Basic.
PRINT "Distance = " ; FNhaversine(36.12, -86.67, 33.94, -118.4) " km" END DEF FNhaversine(n1, e1, n2, e2) LOCAL d() : DIM d(2) d() = COSRAD(e1-e2) * COSRAD(n1) - COSRAD(n2), \ \ SINRAD(e1-e2) * COSRAD(n1), \ \ SINRAD(n1) - SINRAD(n2) = ASN(MOD(d()) / 2) * 6...
Const MER = 6371 Public DEG_TO_RAD As Double Function haversine(lat1 As Double, long1 As Double, lat2 As Double, long2 As Double) As Double lat1 = lat1 * DEG_TO_RAD lat2 = lat2 * DEG_TO_RAD long1 = long1 * DEG_TO_RAD long2 = long2 * DEG_TO_RAD haversine = MER * WorksheetFunction.Acos(Sin(...
Change the programming language of this snippet from BBC_Basic to Go without modifying what it does.
PRINT "Distance = " ; FNhaversine(36.12, -86.67, 33.94, -118.4) " km" END DEF FNhaversine(n1, e1, n2, e2) LOCAL d() : DIM d(2) d() = COSRAD(e1-e2) * COSRAD(n1) - COSRAD(n2), \ \ SINRAD(e1-e2) * COSRAD(n1), \ \ SINRAD(n1) - SINRAD(n2) = ASN(MOD(d()) / 2) * 6...
package main import ( "fmt" "math" ) func haversine(θ float64) float64 { return .5 * (1 - math.Cos(θ)) } type pos struct { φ float64 ψ float64 } func degPos(lat, lon float64) pos { return pos{lat * math.Pi / 180, lon * math.Pi / 180} } const rEarth = 6372.8 func hsDist(p1, p2 pos) float...
Translate the given BBC_Basic code snippet into Go without altering its behavior.
PRINT "Distance = " ; FNhaversine(36.12, -86.67, 33.94, -118.4) " km" END DEF FNhaversine(n1, e1, n2, e2) LOCAL d() : DIM d(2) d() = COSRAD(e1-e2) * COSRAD(n1) - COSRAD(n2), \ \ SINRAD(e1-e2) * COSRAD(n1), \ \ SINRAD(n1) - SINRAD(n2) = ASN(MOD(d()) / 2) * 6...
package main import ( "fmt" "math" ) func haversine(θ float64) float64 { return .5 * (1 - math.Cos(θ)) } type pos struct { φ float64 ψ float64 } func degPos(lat, lon float64) pos { return pos{lat * math.Pi / 180, lon * math.Pi / 180} } const rEarth = 6372.8 func hsDist(p1, p2 pos) float...
Maintain the same structure and functionality when rewriting this code in C.
(defn haversine [{lon1 :longitude lat1 :latitude} {lon2 :longitude lat2 :latitude}] (let [R 6372.8 dlat (Math/toRadians (- lat2 lat1)) dlon (Math/toRadians (- lon2 lon1)) lat1 (Math/toRadians lat1) lat2 (Math/toRadians lat2) a (+ (* (Math/sin (/ dlat 2)) (Math/sin (/ dlat 2)...
#include <stdio.h> #include <stdlib.h> #include <math.h> #define R 6371 #define TO_RAD (3.1415926536 / 180) double dist(double th1, double ph1, double th2, double ph2) { double dx, dy, dz; ph1 -= ph2; ph1 *= TO_RAD, th1 *= TO_RAD, th2 *= TO_RAD; dz = sin(th1) - sin(th2); dx = cos(ph1) * cos(th1) - cos(th2); dy ...
Change the programming language of this snippet from Clojure to C without modifying what it does.
(defn haversine [{lon1 :longitude lat1 :latitude} {lon2 :longitude lat2 :latitude}] (let [R 6372.8 dlat (Math/toRadians (- lat2 lat1)) dlon (Math/toRadians (- lon2 lon1)) lat1 (Math/toRadians lat1) lat2 (Math/toRadians lat2) a (+ (* (Math/sin (/ dlat 2)) (Math/sin (/ dlat 2)...
#include <stdio.h> #include <stdlib.h> #include <math.h> #define R 6371 #define TO_RAD (3.1415926536 / 180) double dist(double th1, double ph1, double th2, double ph2) { double dx, dy, dz; ph1 -= ph2; ph1 *= TO_RAD, th1 *= TO_RAD, th2 *= TO_RAD; dz = sin(th1) - sin(th2); dx = cos(ph1) * cos(th1) - cos(th2); dy ...
Keep all operations the same but rewrite the snippet in C#.
(defn haversine [{lon1 :longitude lat1 :latitude} {lon2 :longitude lat2 :latitude}] (let [R 6372.8 dlat (Math/toRadians (- lat2 lat1)) dlon (Math/toRadians (- lon2 lon1)) lat1 (Math/toRadians lat1) lat2 (Math/toRadians lat2) a (+ (* (Math/sin (/ dlat 2)) (Math/sin (/ dlat 2)...
public static class Haversine { public static double calculate(double lat1, double lon1, double lat2, double lon2) { var R = 6372.8; var dLat = toRadians(lat2 - lat1); var dLon = toRadians(lon2 - lon1); lat1 = toRadians(lat1); lat2 = toRadians(lat2); var a = Math.Sin(dLat / 2) * Math.Sin(...
Port the provided Clojure code into C# while preserving the original functionality.
(defn haversine [{lon1 :longitude lat1 :latitude} {lon2 :longitude lat2 :latitude}] (let [R 6372.8 dlat (Math/toRadians (- lat2 lat1)) dlon (Math/toRadians (- lon2 lon1)) lat1 (Math/toRadians lat1) lat2 (Math/toRadians lat2) a (+ (* (Math/sin (/ dlat 2)) (Math/sin (/ dlat 2)...
public static class Haversine { public static double calculate(double lat1, double lon1, double lat2, double lon2) { var R = 6372.8; var dLat = toRadians(lat2 - lat1); var dLon = toRadians(lon2 - lon1); lat1 = toRadians(lat1); lat2 = toRadians(lat2); var a = Math.Sin(dLat / 2) * Math.Sin(...
Rewrite this program in C++ while keeping its functionality equivalent to the Clojure version.
(defn haversine [{lon1 :longitude lat1 :latitude} {lon2 :longitude lat2 :latitude}] (let [R 6372.8 dlat (Math/toRadians (- lat2 lat1)) dlon (Math/toRadians (- lon2 lon1)) lat1 (Math/toRadians lat1) lat2 (Math/toRadians lat2) a (+ (* (Math/sin (/ dlat 2)) (Math/sin (/ dlat 2)...
#define _USE_MATH_DEFINES #include <math.h> #include <iostream> const static double EarthRadiusKm = 6372.8; inline double DegreeToRadian(double angle) { return M_PI * angle / 180.0; } class Coordinate { public: Coordinate(double latitude ,double longitude):myLatitude(latitude), myLongitude(longitude) {} double...
Port the provided Clojure code into C++ while preserving the original functionality.
(defn haversine [{lon1 :longitude lat1 :latitude} {lon2 :longitude lat2 :latitude}] (let [R 6372.8 dlat (Math/toRadians (- lat2 lat1)) dlon (Math/toRadians (- lon2 lon1)) lat1 (Math/toRadians lat1) lat2 (Math/toRadians lat2) a (+ (* (Math/sin (/ dlat 2)) (Math/sin (/ dlat 2)...
#define _USE_MATH_DEFINES #include <math.h> #include <iostream> const static double EarthRadiusKm = 6372.8; inline double DegreeToRadian(double angle) { return M_PI * angle / 180.0; } class Coordinate { public: Coordinate(double latitude ,double longitude):myLatitude(latitude), myLongitude(longitude) {} double...
Write the same code in Java as shown below in Clojure.
(defn haversine [{lon1 :longitude lat1 :latitude} {lon2 :longitude lat2 :latitude}] (let [R 6372.8 dlat (Math/toRadians (- lat2 lat1)) dlon (Math/toRadians (- lon2 lon1)) lat1 (Math/toRadians lat1) lat2 (Math/toRadians lat2) a (+ (* (Math/sin (/ dlat 2)) (Math/sin (/ dlat 2)...
public class Haversine { public static final double R = 6372.8; public static double haversine(double lat1, double lon1, double lat2, double lon2) { lat1 = Math.toRadians(lat1); lat2 = Math.toRadians(lat2); double dLat = lat2 - lat1; double dLon = Math.toRadians(lon2 - lon1); ...
Produce a language-to-language conversion: from Clojure to Java, same semantics.
(defn haversine [{lon1 :longitude lat1 :latitude} {lon2 :longitude lat2 :latitude}] (let [R 6372.8 dlat (Math/toRadians (- lat2 lat1)) dlon (Math/toRadians (- lon2 lon1)) lat1 (Math/toRadians lat1) lat2 (Math/toRadians lat2) a (+ (* (Math/sin (/ dlat 2)) (Math/sin (/ dlat 2)...
public class Haversine { public static final double R = 6372.8; public static double haversine(double lat1, double lon1, double lat2, double lon2) { lat1 = Math.toRadians(lat1); lat2 = Math.toRadians(lat2); double dLat = lat2 - lat1; double dLon = Math.toRadians(lon2 - lon1); ...
Change the following Clojure code into Python without altering its purpose.
(defn haversine [{lon1 :longitude lat1 :latitude} {lon2 :longitude lat2 :latitude}] (let [R 6372.8 dlat (Math/toRadians (- lat2 lat1)) dlon (Math/toRadians (- lon2 lon1)) lat1 (Math/toRadians lat1) lat2 (Math/toRadians lat2) a (+ (* (Math/sin (/ dlat 2)) (Math/sin (/ dlat 2)...
from math import radians, sin, cos, sqrt, asin def haversine(lat1, lon1, lat2, lon2): R = 6372.8 dLat = radians(lat2 - lat1) dLon = radians(lon2 - lon1) lat1 = radians(lat1) lat2 = radians(lat2) a = sin(dLat / 2)**2 + cos(lat1) * cos(lat2) * sin(dLon / 2)**2 c = 2 * asin(sqrt(a)) ...
Produce a language-to-language conversion: from Clojure to Python, same semantics.
(defn haversine [{lon1 :longitude lat1 :latitude} {lon2 :longitude lat2 :latitude}] (let [R 6372.8 dlat (Math/toRadians (- lat2 lat1)) dlon (Math/toRadians (- lon2 lon1)) lat1 (Math/toRadians lat1) lat2 (Math/toRadians lat2) a (+ (* (Math/sin (/ dlat 2)) (Math/sin (/ dlat 2)...
from math import radians, sin, cos, sqrt, asin def haversine(lat1, lon1, lat2, lon2): R = 6372.8 dLat = radians(lat2 - lat1) dLon = radians(lon2 - lon1) lat1 = radians(lat1) lat2 = radians(lat2) a = sin(dLat / 2)**2 + cos(lat1) * cos(lat2) * sin(dLon / 2)**2 c = 2 * asin(sqrt(a)) ...
Change the programming language of this snippet from Clojure to VB without modifying what it does.
(defn haversine [{lon1 :longitude lat1 :latitude} {lon2 :longitude lat2 :latitude}] (let [R 6372.8 dlat (Math/toRadians (- lat2 lat1)) dlon (Math/toRadians (- lon2 lon1)) lat1 (Math/toRadians lat1) lat2 (Math/toRadians lat2) a (+ (* (Math/sin (/ dlat 2)) (Math/sin (/ dlat 2)...
Const MER = 6371 Public DEG_TO_RAD As Double Function haversine(lat1 As Double, long1 As Double, lat2 As Double, long2 As Double) As Double lat1 = lat1 * DEG_TO_RAD lat2 = lat2 * DEG_TO_RAD long1 = long1 * DEG_TO_RAD long2 = long2 * DEG_TO_RAD haversine = MER * WorksheetFunction.Acos(Sin(...
Write a version of this Clojure function in VB with identical behavior.
(defn haversine [{lon1 :longitude lat1 :latitude} {lon2 :longitude lat2 :latitude}] (let [R 6372.8 dlat (Math/toRadians (- lat2 lat1)) dlon (Math/toRadians (- lon2 lon1)) lat1 (Math/toRadians lat1) lat2 (Math/toRadians lat2) a (+ (* (Math/sin (/ dlat 2)) (Math/sin (/ dlat 2)...
Const MER = 6371 Public DEG_TO_RAD As Double Function haversine(lat1 As Double, long1 As Double, lat2 As Double, long2 As Double) As Double lat1 = lat1 * DEG_TO_RAD lat2 = lat2 * DEG_TO_RAD long1 = long1 * DEG_TO_RAD long2 = long2 * DEG_TO_RAD haversine = MER * WorksheetFunction.Acos(Sin(...
Port the following code from Clojure to Go with equivalent syntax and logic.
(defn haversine [{lon1 :longitude lat1 :latitude} {lon2 :longitude lat2 :latitude}] (let [R 6372.8 dlat (Math/toRadians (- lat2 lat1)) dlon (Math/toRadians (- lon2 lon1)) lat1 (Math/toRadians lat1) lat2 (Math/toRadians lat2) a (+ (* (Math/sin (/ dlat 2)) (Math/sin (/ dlat 2)...
package main import ( "fmt" "math" ) func haversine(θ float64) float64 { return .5 * (1 - math.Cos(θ)) } type pos struct { φ float64 ψ float64 } func degPos(lat, lon float64) pos { return pos{lat * math.Pi / 180, lon * math.Pi / 180} } const rEarth = 6372.8 func hsDist(p1, p2 pos) float...
Port the following code from Clojure to Go with equivalent syntax and logic.
(defn haversine [{lon1 :longitude lat1 :latitude} {lon2 :longitude lat2 :latitude}] (let [R 6372.8 dlat (Math/toRadians (- lat2 lat1)) dlon (Math/toRadians (- lon2 lon1)) lat1 (Math/toRadians lat1) lat2 (Math/toRadians lat2) a (+ (* (Math/sin (/ dlat 2)) (Math/sin (/ dlat 2)...
package main import ( "fmt" "math" ) func haversine(θ float64) float64 { return .5 * (1 - math.Cos(θ)) } type pos struct { φ float64 ψ float64 } func degPos(lat, lon float64) pos { return pos{lat * math.Pi / 180, lon * math.Pi / 180} } const rEarth = 6372.8 func hsDist(p1, p2 pos) float...
Can you help me rewrite this code in C instead of Common_Lisp, keeping it the same logically?
(defparameter *earth-radius* 6372.8) (defparameter *rad-conv* (/ pi 180)) (defun deg->rad (x) (* x *rad-conv*)) (defun haversine (x) (expt (sin (/ x 2)) 2)) (defun dist-rad (lat1 lng1 lat2 lng2) (let* ((hlat (haversine (- lat2 lat1))) (hlng (haversine (- lng2 lng1))) (root (sqrt (+ hlat (* (...
#include <stdio.h> #include <stdlib.h> #include <math.h> #define R 6371 #define TO_RAD (3.1415926536 / 180) double dist(double th1, double ph1, double th2, double ph2) { double dx, dy, dz; ph1 -= ph2; ph1 *= TO_RAD, th1 *= TO_RAD, th2 *= TO_RAD; dz = sin(th1) - sin(th2); dx = cos(ph1) * cos(th1) - cos(th2); dy ...
Preserve the algorithm and functionality while converting the code from Common_Lisp to C.
(defparameter *earth-radius* 6372.8) (defparameter *rad-conv* (/ pi 180)) (defun deg->rad (x) (* x *rad-conv*)) (defun haversine (x) (expt (sin (/ x 2)) 2)) (defun dist-rad (lat1 lng1 lat2 lng2) (let* ((hlat (haversine (- lat2 lat1))) (hlng (haversine (- lng2 lng1))) (root (sqrt (+ hlat (* (...
#include <stdio.h> #include <stdlib.h> #include <math.h> #define R 6371 #define TO_RAD (3.1415926536 / 180) double dist(double th1, double ph1, double th2, double ph2) { double dx, dy, dz; ph1 -= ph2; ph1 *= TO_RAD, th1 *= TO_RAD, th2 *= TO_RAD; dz = sin(th1) - sin(th2); dx = cos(ph1) * cos(th1) - cos(th2); dy ...
Convert the following code from Common_Lisp to C#, ensuring the logic remains intact.
(defparameter *earth-radius* 6372.8) (defparameter *rad-conv* (/ pi 180)) (defun deg->rad (x) (* x *rad-conv*)) (defun haversine (x) (expt (sin (/ x 2)) 2)) (defun dist-rad (lat1 lng1 lat2 lng2) (let* ((hlat (haversine (- lat2 lat1))) (hlng (haversine (- lng2 lng1))) (root (sqrt (+ hlat (* (...
public static class Haversine { public static double calculate(double lat1, double lon1, double lat2, double lon2) { var R = 6372.8; var dLat = toRadians(lat2 - lat1); var dLon = toRadians(lon2 - lon1); lat1 = toRadians(lat1); lat2 = toRadians(lat2); var a = Math.Sin(dLat / 2) * Math.Sin(...
Ensure the translated C# code behaves exactly like the original Common_Lisp snippet.
(defparameter *earth-radius* 6372.8) (defparameter *rad-conv* (/ pi 180)) (defun deg->rad (x) (* x *rad-conv*)) (defun haversine (x) (expt (sin (/ x 2)) 2)) (defun dist-rad (lat1 lng1 lat2 lng2) (let* ((hlat (haversine (- lat2 lat1))) (hlng (haversine (- lng2 lng1))) (root (sqrt (+ hlat (* (...
public static class Haversine { public static double calculate(double lat1, double lon1, double lat2, double lon2) { var R = 6372.8; var dLat = toRadians(lat2 - lat1); var dLon = toRadians(lon2 - lon1); lat1 = toRadians(lat1); lat2 = toRadians(lat2); var a = Math.Sin(dLat / 2) * Math.Sin(...
Generate a C++ translation of this Common_Lisp snippet without changing its computational steps.
(defparameter *earth-radius* 6372.8) (defparameter *rad-conv* (/ pi 180)) (defun deg->rad (x) (* x *rad-conv*)) (defun haversine (x) (expt (sin (/ x 2)) 2)) (defun dist-rad (lat1 lng1 lat2 lng2) (let* ((hlat (haversine (- lat2 lat1))) (hlng (haversine (- lng2 lng1))) (root (sqrt (+ hlat (* (...
#define _USE_MATH_DEFINES #include <math.h> #include <iostream> const static double EarthRadiusKm = 6372.8; inline double DegreeToRadian(double angle) { return M_PI * angle / 180.0; } class Coordinate { public: Coordinate(double latitude ,double longitude):myLatitude(latitude), myLongitude(longitude) {} double...
Rewrite the snippet below in C++ so it works the same as the original Common_Lisp code.
(defparameter *earth-radius* 6372.8) (defparameter *rad-conv* (/ pi 180)) (defun deg->rad (x) (* x *rad-conv*)) (defun haversine (x) (expt (sin (/ x 2)) 2)) (defun dist-rad (lat1 lng1 lat2 lng2) (let* ((hlat (haversine (- lat2 lat1))) (hlng (haversine (- lng2 lng1))) (root (sqrt (+ hlat (* (...
#define _USE_MATH_DEFINES #include <math.h> #include <iostream> const static double EarthRadiusKm = 6372.8; inline double DegreeToRadian(double angle) { return M_PI * angle / 180.0; } class Coordinate { public: Coordinate(double latitude ,double longitude):myLatitude(latitude), myLongitude(longitude) {} double...
Produce a functionally identical Java code for the snippet given in Common_Lisp.
(defparameter *earth-radius* 6372.8) (defparameter *rad-conv* (/ pi 180)) (defun deg->rad (x) (* x *rad-conv*)) (defun haversine (x) (expt (sin (/ x 2)) 2)) (defun dist-rad (lat1 lng1 lat2 lng2) (let* ((hlat (haversine (- lat2 lat1))) (hlng (haversine (- lng2 lng1))) (root (sqrt (+ hlat (* (...
public class Haversine { public static final double R = 6372.8; public static double haversine(double lat1, double lon1, double lat2, double lon2) { lat1 = Math.toRadians(lat1); lat2 = Math.toRadians(lat2); double dLat = lat2 - lat1; double dLon = Math.toRadians(lon2 - lon1); ...
Rewrite the snippet below in Java so it works the same as the original Common_Lisp code.
(defparameter *earth-radius* 6372.8) (defparameter *rad-conv* (/ pi 180)) (defun deg->rad (x) (* x *rad-conv*)) (defun haversine (x) (expt (sin (/ x 2)) 2)) (defun dist-rad (lat1 lng1 lat2 lng2) (let* ((hlat (haversine (- lat2 lat1))) (hlng (haversine (- lng2 lng1))) (root (sqrt (+ hlat (* (...
public class Haversine { public static final double R = 6372.8; public static double haversine(double lat1, double lon1, double lat2, double lon2) { lat1 = Math.toRadians(lat1); lat2 = Math.toRadians(lat2); double dLat = lat2 - lat1; double dLon = Math.toRadians(lon2 - lon1); ...
Convert this Common_Lisp block to Python, preserving its control flow and logic.
(defparameter *earth-radius* 6372.8) (defparameter *rad-conv* (/ pi 180)) (defun deg->rad (x) (* x *rad-conv*)) (defun haversine (x) (expt (sin (/ x 2)) 2)) (defun dist-rad (lat1 lng1 lat2 lng2) (let* ((hlat (haversine (- lat2 lat1))) (hlng (haversine (- lng2 lng1))) (root (sqrt (+ hlat (* (...
from math import radians, sin, cos, sqrt, asin def haversine(lat1, lon1, lat2, lon2): R = 6372.8 dLat = radians(lat2 - lat1) dLon = radians(lon2 - lon1) lat1 = radians(lat1) lat2 = radians(lat2) a = sin(dLat / 2)**2 + cos(lat1) * cos(lat2) * sin(dLon / 2)**2 c = 2 * asin(sqrt(a)) ...
Change the programming language of this snippet from Common_Lisp to Python without modifying what it does.
(defparameter *earth-radius* 6372.8) (defparameter *rad-conv* (/ pi 180)) (defun deg->rad (x) (* x *rad-conv*)) (defun haversine (x) (expt (sin (/ x 2)) 2)) (defun dist-rad (lat1 lng1 lat2 lng2) (let* ((hlat (haversine (- lat2 lat1))) (hlng (haversine (- lng2 lng1))) (root (sqrt (+ hlat (* (...
from math import radians, sin, cos, sqrt, asin def haversine(lat1, lon1, lat2, lon2): R = 6372.8 dLat = radians(lat2 - lat1) dLon = radians(lon2 - lon1) lat1 = radians(lat1) lat2 = radians(lat2) a = sin(dLat / 2)**2 + cos(lat1) * cos(lat2) * sin(dLon / 2)**2 c = 2 * asin(sqrt(a)) ...
Change the following Common_Lisp code into VB without altering its purpose.
(defparameter *earth-radius* 6372.8) (defparameter *rad-conv* (/ pi 180)) (defun deg->rad (x) (* x *rad-conv*)) (defun haversine (x) (expt (sin (/ x 2)) 2)) (defun dist-rad (lat1 lng1 lat2 lng2) (let* ((hlat (haversine (- lat2 lat1))) (hlng (haversine (- lng2 lng1))) (root (sqrt (+ hlat (* (...
Const MER = 6371 Public DEG_TO_RAD As Double Function haversine(lat1 As Double, long1 As Double, lat2 As Double, long2 As Double) As Double lat1 = lat1 * DEG_TO_RAD lat2 = lat2 * DEG_TO_RAD long1 = long1 * DEG_TO_RAD long2 = long2 * DEG_TO_RAD haversine = MER * WorksheetFunction.Acos(Sin(...
Transform the following Common_Lisp implementation into VB, maintaining the same output and logic.
(defparameter *earth-radius* 6372.8) (defparameter *rad-conv* (/ pi 180)) (defun deg->rad (x) (* x *rad-conv*)) (defun haversine (x) (expt (sin (/ x 2)) 2)) (defun dist-rad (lat1 lng1 lat2 lng2) (let* ((hlat (haversine (- lat2 lat1))) (hlng (haversine (- lng2 lng1))) (root (sqrt (+ hlat (* (...
Const MER = 6371 Public DEG_TO_RAD As Double Function haversine(lat1 As Double, long1 As Double, lat2 As Double, long2 As Double) As Double lat1 = lat1 * DEG_TO_RAD lat2 = lat2 * DEG_TO_RAD long1 = long1 * DEG_TO_RAD long2 = long2 * DEG_TO_RAD haversine = MER * WorksheetFunction.Acos(Sin(...
Please provide an equivalent version of this Common_Lisp code in Go.
(defparameter *earth-radius* 6372.8) (defparameter *rad-conv* (/ pi 180)) (defun deg->rad (x) (* x *rad-conv*)) (defun haversine (x) (expt (sin (/ x 2)) 2)) (defun dist-rad (lat1 lng1 lat2 lng2) (let* ((hlat (haversine (- lat2 lat1))) (hlng (haversine (- lng2 lng1))) (root (sqrt (+ hlat (* (...
package main import ( "fmt" "math" ) func haversine(θ float64) float64 { return .5 * (1 - math.Cos(θ)) } type pos struct { φ float64 ψ float64 } func degPos(lat, lon float64) pos { return pos{lat * math.Pi / 180, lon * math.Pi / 180} } const rEarth = 6372.8 func hsDist(p1, p2 pos) float...
Translate this program into Go but keep the logic exactly as in Common_Lisp.
(defparameter *earth-radius* 6372.8) (defparameter *rad-conv* (/ pi 180)) (defun deg->rad (x) (* x *rad-conv*)) (defun haversine (x) (expt (sin (/ x 2)) 2)) (defun dist-rad (lat1 lng1 lat2 lng2) (let* ((hlat (haversine (- lat2 lat1))) (hlng (haversine (- lng2 lng1))) (root (sqrt (+ hlat (* (...
package main import ( "fmt" "math" ) func haversine(θ float64) float64 { return .5 * (1 - math.Cos(θ)) } type pos struct { φ float64 ψ float64 } func degPos(lat, lon float64) pos { return pos{lat * math.Pi / 180, lon * math.Pi / 180} } const rEarth = 6372.8 func hsDist(p1, p2 pos) float...
Change the programming language of this snippet from D to C without modifying what it does.
import std.stdio, std.math; real haversineDistance(in real dth1, in real dph1, in real dth2, in real dph2) pure nothrow @nogc { enum real R = 6371; enum real TO_RAD = PI / 180; alias imr = immutable real; imr ph1d = dph1 - dph2; imr ph1 = ph1d * TO_RAD; imr th1 = dth1 * ...
#include <stdio.h> #include <stdlib.h> #include <math.h> #define R 6371 #define TO_RAD (3.1415926536 / 180) double dist(double th1, double ph1, double th2, double ph2) { double dx, dy, dz; ph1 -= ph2; ph1 *= TO_RAD, th1 *= TO_RAD, th2 *= TO_RAD; dz = sin(th1) - sin(th2); dx = cos(ph1) * cos(th1) - cos(th2); dy ...
Rewrite the snippet below in C so it works the same as the original D code.
import std.stdio, std.math; real haversineDistance(in real dth1, in real dph1, in real dth2, in real dph2) pure nothrow @nogc { enum real R = 6371; enum real TO_RAD = PI / 180; alias imr = immutable real; imr ph1d = dph1 - dph2; imr ph1 = ph1d * TO_RAD; imr th1 = dth1 * ...
#include <stdio.h> #include <stdlib.h> #include <math.h> #define R 6371 #define TO_RAD (3.1415926536 / 180) double dist(double th1, double ph1, double th2, double ph2) { double dx, dy, dz; ph1 -= ph2; ph1 *= TO_RAD, th1 *= TO_RAD, th2 *= TO_RAD; dz = sin(th1) - sin(th2); dx = cos(ph1) * cos(th1) - cos(th2); dy ...
Write a version of this D function in C# with identical behavior.
import std.stdio, std.math; real haversineDistance(in real dth1, in real dph1, in real dth2, in real dph2) pure nothrow @nogc { enum real R = 6371; enum real TO_RAD = PI / 180; alias imr = immutable real; imr ph1d = dph1 - dph2; imr ph1 = ph1d * TO_RAD; imr th1 = dth1 * ...
public static class Haversine { public static double calculate(double lat1, double lon1, double lat2, double lon2) { var R = 6372.8; var dLat = toRadians(lat2 - lat1); var dLon = toRadians(lon2 - lon1); lat1 = toRadians(lat1); lat2 = toRadians(lat2); var a = Math.Sin(dLat / 2) * Math.Sin(...
Translate the given D code snippet into C# without altering its behavior.
import std.stdio, std.math; real haversineDistance(in real dth1, in real dph1, in real dth2, in real dph2) pure nothrow @nogc { enum real R = 6371; enum real TO_RAD = PI / 180; alias imr = immutable real; imr ph1d = dph1 - dph2; imr ph1 = ph1d * TO_RAD; imr th1 = dth1 * ...
public static class Haversine { public static double calculate(double lat1, double lon1, double lat2, double lon2) { var R = 6372.8; var dLat = toRadians(lat2 - lat1); var dLon = toRadians(lon2 - lon1); lat1 = toRadians(lat1); lat2 = toRadians(lat2); var a = Math.Sin(dLat / 2) * Math.Sin(...
Translate this program into C++ but keep the logic exactly as in D.
import std.stdio, std.math; real haversineDistance(in real dth1, in real dph1, in real dth2, in real dph2) pure nothrow @nogc { enum real R = 6371; enum real TO_RAD = PI / 180; alias imr = immutable real; imr ph1d = dph1 - dph2; imr ph1 = ph1d * TO_RAD; imr th1 = dth1 * ...
#define _USE_MATH_DEFINES #include <math.h> #include <iostream> const static double EarthRadiusKm = 6372.8; inline double DegreeToRadian(double angle) { return M_PI * angle / 180.0; } class Coordinate { public: Coordinate(double latitude ,double longitude):myLatitude(latitude), myLongitude(longitude) {} double...
Port the following code from D to C++ with equivalent syntax and logic.
import std.stdio, std.math; real haversineDistance(in real dth1, in real dph1, in real dth2, in real dph2) pure nothrow @nogc { enum real R = 6371; enum real TO_RAD = PI / 180; alias imr = immutable real; imr ph1d = dph1 - dph2; imr ph1 = ph1d * TO_RAD; imr th1 = dth1 * ...
#define _USE_MATH_DEFINES #include <math.h> #include <iostream> const static double EarthRadiusKm = 6372.8; inline double DegreeToRadian(double angle) { return M_PI * angle / 180.0; } class Coordinate { public: Coordinate(double latitude ,double longitude):myLatitude(latitude), myLongitude(longitude) {} double...
Generate a Java translation of this D snippet without changing its computational steps.
import std.stdio, std.math; real haversineDistance(in real dth1, in real dph1, in real dth2, in real dph2) pure nothrow @nogc { enum real R = 6371; enum real TO_RAD = PI / 180; alias imr = immutable real; imr ph1d = dph1 - dph2; imr ph1 = ph1d * TO_RAD; imr th1 = dth1 * ...
public class Haversine { public static final double R = 6372.8; public static double haversine(double lat1, double lon1, double lat2, double lon2) { lat1 = Math.toRadians(lat1); lat2 = Math.toRadians(lat2); double dLat = lat2 - lat1; double dLon = Math.toRadians(lon2 - lon1); ...
Write a version of this D function in Java with identical behavior.
import std.stdio, std.math; real haversineDistance(in real dth1, in real dph1, in real dth2, in real dph2) pure nothrow @nogc { enum real R = 6371; enum real TO_RAD = PI / 180; alias imr = immutable real; imr ph1d = dph1 - dph2; imr ph1 = ph1d * TO_RAD; imr th1 = dth1 * ...
public class Haversine { public static final double R = 6372.8; public static double haversine(double lat1, double lon1, double lat2, double lon2) { lat1 = Math.toRadians(lat1); lat2 = Math.toRadians(lat2); double dLat = lat2 - lat1; double dLon = Math.toRadians(lon2 - lon1); ...
Write the same code in Python as shown below in D.
import std.stdio, std.math; real haversineDistance(in real dth1, in real dph1, in real dth2, in real dph2) pure nothrow @nogc { enum real R = 6371; enum real TO_RAD = PI / 180; alias imr = immutable real; imr ph1d = dph1 - dph2; imr ph1 = ph1d * TO_RAD; imr th1 = dth1 * ...
from math import radians, sin, cos, sqrt, asin def haversine(lat1, lon1, lat2, lon2): R = 6372.8 dLat = radians(lat2 - lat1) dLon = radians(lon2 - lon1) lat1 = radians(lat1) lat2 = radians(lat2) a = sin(dLat / 2)**2 + cos(lat1) * cos(lat2) * sin(dLon / 2)**2 c = 2 * asin(sqrt(a)) ...
Port the following code from D to Python with equivalent syntax and logic.
import std.stdio, std.math; real haversineDistance(in real dth1, in real dph1, in real dth2, in real dph2) pure nothrow @nogc { enum real R = 6371; enum real TO_RAD = PI / 180; alias imr = immutable real; imr ph1d = dph1 - dph2; imr ph1 = ph1d * TO_RAD; imr th1 = dth1 * ...
from math import radians, sin, cos, sqrt, asin def haversine(lat1, lon1, lat2, lon2): R = 6372.8 dLat = radians(lat2 - lat1) dLon = radians(lon2 - lon1) lat1 = radians(lat1) lat2 = radians(lat2) a = sin(dLat / 2)**2 + cos(lat1) * cos(lat2) * sin(dLon / 2)**2 c = 2 * asin(sqrt(a)) ...
Port the provided D code into VB while preserving the original functionality.
import std.stdio, std.math; real haversineDistance(in real dth1, in real dph1, in real dth2, in real dph2) pure nothrow @nogc { enum real R = 6371; enum real TO_RAD = PI / 180; alias imr = immutable real; imr ph1d = dph1 - dph2; imr ph1 = ph1d * TO_RAD; imr th1 = dth1 * ...
Const MER = 6371 Public DEG_TO_RAD As Double Function haversine(lat1 As Double, long1 As Double, lat2 As Double, long2 As Double) As Double lat1 = lat1 * DEG_TO_RAD lat2 = lat2 * DEG_TO_RAD long1 = long1 * DEG_TO_RAD long2 = long2 * DEG_TO_RAD haversine = MER * WorksheetFunction.Acos(Sin(...
Generate a VB translation of this D snippet without changing its computational steps.
import std.stdio, std.math; real haversineDistance(in real dth1, in real dph1, in real dth2, in real dph2) pure nothrow @nogc { enum real R = 6371; enum real TO_RAD = PI / 180; alias imr = immutable real; imr ph1d = dph1 - dph2; imr ph1 = ph1d * TO_RAD; imr th1 = dth1 * ...
Const MER = 6371 Public DEG_TO_RAD As Double Function haversine(lat1 As Double, long1 As Double, lat2 As Double, long2 As Double) As Double lat1 = lat1 * DEG_TO_RAD lat2 = lat2 * DEG_TO_RAD long1 = long1 * DEG_TO_RAD long2 = long2 * DEG_TO_RAD haversine = MER * WorksheetFunction.Acos(Sin(...
Ensure the translated Go code behaves exactly like the original D snippet.
import std.stdio, std.math; real haversineDistance(in real dth1, in real dph1, in real dth2, in real dph2) pure nothrow @nogc { enum real R = 6371; enum real TO_RAD = PI / 180; alias imr = immutable real; imr ph1d = dph1 - dph2; imr ph1 = ph1d * TO_RAD; imr th1 = dth1 * ...
package main import ( "fmt" "math" ) func haversine(θ float64) float64 { return .5 * (1 - math.Cos(θ)) } type pos struct { φ float64 ψ float64 } func degPos(lat, lon float64) pos { return pos{lat * math.Pi / 180, lon * math.Pi / 180} } const rEarth = 6372.8 func hsDist(p1, p2 pos) float...
Change the following D code into Go without altering its purpose.
import std.stdio, std.math; real haversineDistance(in real dth1, in real dph1, in real dth2, in real dph2) pure nothrow @nogc { enum real R = 6371; enum real TO_RAD = PI / 180; alias imr = immutable real; imr ph1d = dph1 - dph2; imr ph1 = ph1d * TO_RAD; imr th1 = dth1 * ...
package main import ( "fmt" "math" ) func haversine(θ float64) float64 { return .5 * (1 - math.Cos(θ)) } type pos struct { φ float64 ψ float64 } func degPos(lat, lon float64) pos { return pos{lat * math.Pi / 180, lon * math.Pi / 180} } const rEarth = 6372.8 func hsDist(p1, p2 pos) float...
Port the provided Delphi code into C while preserving the original functionality.
program HaversineDemo; uses Math; function HaversineDist(th1, ph1, th2, ph2:double):double; const diameter = 2 * 6372.8; var dx, dy, dz:double; begin ph1 := degtorad(ph1 - ph2); th1 := degtorad(th1); th2 := degtorad(th2); dz := sin(th1) - sin(th2); dx := cos(ph1) * cos(th1) - cos(th2); ...
#include <stdio.h> #include <stdlib.h> #include <math.h> #define R 6371 #define TO_RAD (3.1415926536 / 180) double dist(double th1, double ph1, double th2, double ph2) { double dx, dy, dz; ph1 -= ph2; ph1 *= TO_RAD, th1 *= TO_RAD, th2 *= TO_RAD; dz = sin(th1) - sin(th2); dx = cos(ph1) * cos(th1) - cos(th2); dy ...
Convert this Delphi block to C, preserving its control flow and logic.
program HaversineDemo; uses Math; function HaversineDist(th1, ph1, th2, ph2:double):double; const diameter = 2 * 6372.8; var dx, dy, dz:double; begin ph1 := degtorad(ph1 - ph2); th1 := degtorad(th1); th2 := degtorad(th2); dz := sin(th1) - sin(th2); dx := cos(ph1) * cos(th1) - cos(th2); ...
#include <stdio.h> #include <stdlib.h> #include <math.h> #define R 6371 #define TO_RAD (3.1415926536 / 180) double dist(double th1, double ph1, double th2, double ph2) { double dx, dy, dz; ph1 -= ph2; ph1 *= TO_RAD, th1 *= TO_RAD, th2 *= TO_RAD; dz = sin(th1) - sin(th2); dx = cos(ph1) * cos(th1) - cos(th2); dy ...
Generate an equivalent C# version of this Delphi code.
program HaversineDemo; uses Math; function HaversineDist(th1, ph1, th2, ph2:double):double; const diameter = 2 * 6372.8; var dx, dy, dz:double; begin ph1 := degtorad(ph1 - ph2); th1 := degtorad(th1); th2 := degtorad(th2); dz := sin(th1) - sin(th2); dx := cos(ph1) * cos(th1) - cos(th2); ...
public static class Haversine { public static double calculate(double lat1, double lon1, double lat2, double lon2) { var R = 6372.8; var dLat = toRadians(lat2 - lat1); var dLon = toRadians(lon2 - lon1); lat1 = toRadians(lat1); lat2 = toRadians(lat2); var a = Math.Sin(dLat / 2) * Math.Sin(...
Ensure the translated C# code behaves exactly like the original Delphi snippet.
program HaversineDemo; uses Math; function HaversineDist(th1, ph1, th2, ph2:double):double; const diameter = 2 * 6372.8; var dx, dy, dz:double; begin ph1 := degtorad(ph1 - ph2); th1 := degtorad(th1); th2 := degtorad(th2); dz := sin(th1) - sin(th2); dx := cos(ph1) * cos(th1) - cos(th2); ...
public static class Haversine { public static double calculate(double lat1, double lon1, double lat2, double lon2) { var R = 6372.8; var dLat = toRadians(lat2 - lat1); var dLon = toRadians(lon2 - lon1); lat1 = toRadians(lat1); lat2 = toRadians(lat2); var a = Math.Sin(dLat / 2) * Math.Sin(...
Write a version of this Delphi function in C++ with identical behavior.
program HaversineDemo; uses Math; function HaversineDist(th1, ph1, th2, ph2:double):double; const diameter = 2 * 6372.8; var dx, dy, dz:double; begin ph1 := degtorad(ph1 - ph2); th1 := degtorad(th1); th2 := degtorad(th2); dz := sin(th1) - sin(th2); dx := cos(ph1) * cos(th1) - cos(th2); ...
#define _USE_MATH_DEFINES #include <math.h> #include <iostream> const static double EarthRadiusKm = 6372.8; inline double DegreeToRadian(double angle) { return M_PI * angle / 180.0; } class Coordinate { public: Coordinate(double latitude ,double longitude):myLatitude(latitude), myLongitude(longitude) {} double...
Port the provided Delphi code into C++ while preserving the original functionality.
program HaversineDemo; uses Math; function HaversineDist(th1, ph1, th2, ph2:double):double; const diameter = 2 * 6372.8; var dx, dy, dz:double; begin ph1 := degtorad(ph1 - ph2); th1 := degtorad(th1); th2 := degtorad(th2); dz := sin(th1) - sin(th2); dx := cos(ph1) * cos(th1) - cos(th2); ...
#define _USE_MATH_DEFINES #include <math.h> #include <iostream> const static double EarthRadiusKm = 6372.8; inline double DegreeToRadian(double angle) { return M_PI * angle / 180.0; } class Coordinate { public: Coordinate(double latitude ,double longitude):myLatitude(latitude), myLongitude(longitude) {} double...
Write the same code in Java as shown below in Delphi.
program HaversineDemo; uses Math; function HaversineDist(th1, ph1, th2, ph2:double):double; const diameter = 2 * 6372.8; var dx, dy, dz:double; begin ph1 := degtorad(ph1 - ph2); th1 := degtorad(th1); th2 := degtorad(th2); dz := sin(th1) - sin(th2); dx := cos(ph1) * cos(th1) - cos(th2); ...
public class Haversine { public static final double R = 6372.8; public static double haversine(double lat1, double lon1, double lat2, double lon2) { lat1 = Math.toRadians(lat1); lat2 = Math.toRadians(lat2); double dLat = lat2 - lat1; double dLon = Math.toRadians(lon2 - lon1); ...
Generate an equivalent Java version of this Delphi code.
program HaversineDemo; uses Math; function HaversineDist(th1, ph1, th2, ph2:double):double; const diameter = 2 * 6372.8; var dx, dy, dz:double; begin ph1 := degtorad(ph1 - ph2); th1 := degtorad(th1); th2 := degtorad(th2); dz := sin(th1) - sin(th2); dx := cos(ph1) * cos(th1) - cos(th2); ...
public class Haversine { public static final double R = 6372.8; public static double haversine(double lat1, double lon1, double lat2, double lon2) { lat1 = Math.toRadians(lat1); lat2 = Math.toRadians(lat2); double dLat = lat2 - lat1; double dLon = Math.toRadians(lon2 - lon1); ...
Translate the given Delphi code snippet into Python without altering its behavior.
program HaversineDemo; uses Math; function HaversineDist(th1, ph1, th2, ph2:double):double; const diameter = 2 * 6372.8; var dx, dy, dz:double; begin ph1 := degtorad(ph1 - ph2); th1 := degtorad(th1); th2 := degtorad(th2); dz := sin(th1) - sin(th2); dx := cos(ph1) * cos(th1) - cos(th2); ...
from math import radians, sin, cos, sqrt, asin def haversine(lat1, lon1, lat2, lon2): R = 6372.8 dLat = radians(lat2 - lat1) dLon = radians(lon2 - lon1) lat1 = radians(lat1) lat2 = radians(lat2) a = sin(dLat / 2)**2 + cos(lat1) * cos(lat2) * sin(dLon / 2)**2 c = 2 * asin(sqrt(a)) ...
Change the programming language of this snippet from Delphi to Python without modifying what it does.
program HaversineDemo; uses Math; function HaversineDist(th1, ph1, th2, ph2:double):double; const diameter = 2 * 6372.8; var dx, dy, dz:double; begin ph1 := degtorad(ph1 - ph2); th1 := degtorad(th1); th2 := degtorad(th2); dz := sin(th1) - sin(th2); dx := cos(ph1) * cos(th1) - cos(th2); ...
from math import radians, sin, cos, sqrt, asin def haversine(lat1, lon1, lat2, lon2): R = 6372.8 dLat = radians(lat2 - lat1) dLon = radians(lon2 - lon1) lat1 = radians(lat1) lat2 = radians(lat2) a = sin(dLat / 2)**2 + cos(lat1) * cos(lat2) * sin(dLon / 2)**2 c = 2 * asin(sqrt(a)) ...
Write the same algorithm in VB as shown in this Delphi implementation.
program HaversineDemo; uses Math; function HaversineDist(th1, ph1, th2, ph2:double):double; const diameter = 2 * 6372.8; var dx, dy, dz:double; begin ph1 := degtorad(ph1 - ph2); th1 := degtorad(th1); th2 := degtorad(th2); dz := sin(th1) - sin(th2); dx := cos(ph1) * cos(th1) - cos(th2); ...
Const MER = 6371 Public DEG_TO_RAD As Double Function haversine(lat1 As Double, long1 As Double, lat2 As Double, long2 As Double) As Double lat1 = lat1 * DEG_TO_RAD lat2 = lat2 * DEG_TO_RAD long1 = long1 * DEG_TO_RAD long2 = long2 * DEG_TO_RAD haversine = MER * WorksheetFunction.Acos(Sin(...
Please provide an equivalent version of this Delphi code in VB.
program HaversineDemo; uses Math; function HaversineDist(th1, ph1, th2, ph2:double):double; const diameter = 2 * 6372.8; var dx, dy, dz:double; begin ph1 := degtorad(ph1 - ph2); th1 := degtorad(th1); th2 := degtorad(th2); dz := sin(th1) - sin(th2); dx := cos(ph1) * cos(th1) - cos(th2); ...
Const MER = 6371 Public DEG_TO_RAD As Double Function haversine(lat1 As Double, long1 As Double, lat2 As Double, long2 As Double) As Double lat1 = lat1 * DEG_TO_RAD lat2 = lat2 * DEG_TO_RAD long1 = long1 * DEG_TO_RAD long2 = long2 * DEG_TO_RAD haversine = MER * WorksheetFunction.Acos(Sin(...
Convert the following code from Delphi to Go, ensuring the logic remains intact.
program HaversineDemo; uses Math; function HaversineDist(th1, ph1, th2, ph2:double):double; const diameter = 2 * 6372.8; var dx, dy, dz:double; begin ph1 := degtorad(ph1 - ph2); th1 := degtorad(th1); th2 := degtorad(th2); dz := sin(th1) - sin(th2); dx := cos(ph1) * cos(th1) - cos(th2); ...
package main import ( "fmt" "math" ) func haversine(θ float64) float64 { return .5 * (1 - math.Cos(θ)) } type pos struct { φ float64 ψ float64 } func degPos(lat, lon float64) pos { return pos{lat * math.Pi / 180, lon * math.Pi / 180} } const rEarth = 6372.8 func hsDist(p1, p2 pos) float...
Generate an equivalent Go version of this Delphi code.
program HaversineDemo; uses Math; function HaversineDist(th1, ph1, th2, ph2:double):double; const diameter = 2 * 6372.8; var dx, dy, dz:double; begin ph1 := degtorad(ph1 - ph2); th1 := degtorad(th1); th2 := degtorad(th2); dz := sin(th1) - sin(th2); dx := cos(ph1) * cos(th1) - cos(th2); ...
package main import ( "fmt" "math" ) func haversine(θ float64) float64 { return .5 * (1 - math.Cos(θ)) } type pos struct { φ float64 ψ float64 } func degPos(lat, lon float64) pos { return pos{lat * math.Pi / 180, lon * math.Pi / 180} } const rEarth = 6372.8 func hsDist(p1, p2 pos) float...
Please provide an equivalent version of this Elixir code in C.
defmodule Haversine do @v :math.pi / 180 @r 6372.8 def distance({lat1, long1}, {lat2, long2}) do dlat = :math.sin((lat2 - lat1) * @v / 2) dlong = :math.sin((long2 - long1) * @v / 2) a = dlat * dlat + dlong * dlong * :math.cos(lat1 * @v) * :math.cos(lat2 * @v) @r * 2 * :math.asin(:ma...
#include <stdio.h> #include <stdlib.h> #include <math.h> #define R 6371 #define TO_RAD (3.1415926536 / 180) double dist(double th1, double ph1, double th2, double ph2) { double dx, dy, dz; ph1 -= ph2; ph1 *= TO_RAD, th1 *= TO_RAD, th2 *= TO_RAD; dz = sin(th1) - sin(th2); dx = cos(ph1) * cos(th1) - cos(th2); dy ...
Write the same code in C as shown below in Elixir.
defmodule Haversine do @v :math.pi / 180 @r 6372.8 def distance({lat1, long1}, {lat2, long2}) do dlat = :math.sin((lat2 - lat1) * @v / 2) dlong = :math.sin((long2 - long1) * @v / 2) a = dlat * dlat + dlong * dlong * :math.cos(lat1 * @v) * :math.cos(lat2 * @v) @r * 2 * :math.asin(:ma...
#include <stdio.h> #include <stdlib.h> #include <math.h> #define R 6371 #define TO_RAD (3.1415926536 / 180) double dist(double th1, double ph1, double th2, double ph2) { double dx, dy, dz; ph1 -= ph2; ph1 *= TO_RAD, th1 *= TO_RAD, th2 *= TO_RAD; dz = sin(th1) - sin(th2); dx = cos(ph1) * cos(th1) - cos(th2); dy ...
Translate the given Elixir code snippet into C# without altering its behavior.
defmodule Haversine do @v :math.pi / 180 @r 6372.8 def distance({lat1, long1}, {lat2, long2}) do dlat = :math.sin((lat2 - lat1) * @v / 2) dlong = :math.sin((long2 - long1) * @v / 2) a = dlat * dlat + dlong * dlong * :math.cos(lat1 * @v) * :math.cos(lat2 * @v) @r * 2 * :math.asin(:ma...
public static class Haversine { public static double calculate(double lat1, double lon1, double lat2, double lon2) { var R = 6372.8; var dLat = toRadians(lat2 - lat1); var dLon = toRadians(lon2 - lon1); lat1 = toRadians(lat1); lat2 = toRadians(lat2); var a = Math.Sin(dLat / 2) * Math.Sin(...
Preserve the algorithm and functionality while converting the code from Elixir to C#.
defmodule Haversine do @v :math.pi / 180 @r 6372.8 def distance({lat1, long1}, {lat2, long2}) do dlat = :math.sin((lat2 - lat1) * @v / 2) dlong = :math.sin((long2 - long1) * @v / 2) a = dlat * dlat + dlong * dlong * :math.cos(lat1 * @v) * :math.cos(lat2 * @v) @r * 2 * :math.asin(:ma...
public static class Haversine { public static double calculate(double lat1, double lon1, double lat2, double lon2) { var R = 6372.8; var dLat = toRadians(lat2 - lat1); var dLon = toRadians(lon2 - lon1); lat1 = toRadians(lat1); lat2 = toRadians(lat2); var a = Math.Sin(dLat / 2) * Math.Sin(...
Write a version of this Elixir function in C++ with identical behavior.
defmodule Haversine do @v :math.pi / 180 @r 6372.8 def distance({lat1, long1}, {lat2, long2}) do dlat = :math.sin((lat2 - lat1) * @v / 2) dlong = :math.sin((long2 - long1) * @v / 2) a = dlat * dlat + dlong * dlong * :math.cos(lat1 * @v) * :math.cos(lat2 * @v) @r * 2 * :math.asin(:ma...
#define _USE_MATH_DEFINES #include <math.h> #include <iostream> const static double EarthRadiusKm = 6372.8; inline double DegreeToRadian(double angle) { return M_PI * angle / 180.0; } class Coordinate { public: Coordinate(double latitude ,double longitude):myLatitude(latitude), myLongitude(longitude) {} double...
Generate an equivalent C++ version of this Elixir code.
defmodule Haversine do @v :math.pi / 180 @r 6372.8 def distance({lat1, long1}, {lat2, long2}) do dlat = :math.sin((lat2 - lat1) * @v / 2) dlong = :math.sin((long2 - long1) * @v / 2) a = dlat * dlat + dlong * dlong * :math.cos(lat1 * @v) * :math.cos(lat2 * @v) @r * 2 * :math.asin(:ma...
#define _USE_MATH_DEFINES #include <math.h> #include <iostream> const static double EarthRadiusKm = 6372.8; inline double DegreeToRadian(double angle) { return M_PI * angle / 180.0; } class Coordinate { public: Coordinate(double latitude ,double longitude):myLatitude(latitude), myLongitude(longitude) {} double...
Translate the given Elixir code snippet into Java without altering its behavior.
defmodule Haversine do @v :math.pi / 180 @r 6372.8 def distance({lat1, long1}, {lat2, long2}) do dlat = :math.sin((lat2 - lat1) * @v / 2) dlong = :math.sin((long2 - long1) * @v / 2) a = dlat * dlat + dlong * dlong * :math.cos(lat1 * @v) * :math.cos(lat2 * @v) @r * 2 * :math.asin(:ma...
public class Haversine { public static final double R = 6372.8; public static double haversine(double lat1, double lon1, double lat2, double lon2) { lat1 = Math.toRadians(lat1); lat2 = Math.toRadians(lat2); double dLat = lat2 - lat1; double dLon = Math.toRadians(lon2 - lon1); ...
Write the same algorithm in Java as shown in this Elixir implementation.
defmodule Haversine do @v :math.pi / 180 @r 6372.8 def distance({lat1, long1}, {lat2, long2}) do dlat = :math.sin((lat2 - lat1) * @v / 2) dlong = :math.sin((long2 - long1) * @v / 2) a = dlat * dlat + dlong * dlong * :math.cos(lat1 * @v) * :math.cos(lat2 * @v) @r * 2 * :math.asin(:ma...
public class Haversine { public static final double R = 6372.8; public static double haversine(double lat1, double lon1, double lat2, double lon2) { lat1 = Math.toRadians(lat1); lat2 = Math.toRadians(lat2); double dLat = lat2 - lat1; double dLon = Math.toRadians(lon2 - lon1); ...
Ensure the translated Python code behaves exactly like the original Elixir snippet.
defmodule Haversine do @v :math.pi / 180 @r 6372.8 def distance({lat1, long1}, {lat2, long2}) do dlat = :math.sin((lat2 - lat1) * @v / 2) dlong = :math.sin((long2 - long1) * @v / 2) a = dlat * dlat + dlong * dlong * :math.cos(lat1 * @v) * :math.cos(lat2 * @v) @r * 2 * :math.asin(:ma...
from math import radians, sin, cos, sqrt, asin def haversine(lat1, lon1, lat2, lon2): R = 6372.8 dLat = radians(lat2 - lat1) dLon = radians(lon2 - lon1) lat1 = radians(lat1) lat2 = radians(lat2) a = sin(dLat / 2)**2 + cos(lat1) * cos(lat2) * sin(dLon / 2)**2 c = 2 * asin(sqrt(a)) ...
Maintain the same structure and functionality when rewriting this code in Python.
defmodule Haversine do @v :math.pi / 180 @r 6372.8 def distance({lat1, long1}, {lat2, long2}) do dlat = :math.sin((lat2 - lat1) * @v / 2) dlong = :math.sin((long2 - long1) * @v / 2) a = dlat * dlat + dlong * dlong * :math.cos(lat1 * @v) * :math.cos(lat2 * @v) @r * 2 * :math.asin(:ma...
from math import radians, sin, cos, sqrt, asin def haversine(lat1, lon1, lat2, lon2): R = 6372.8 dLat = radians(lat2 - lat1) dLon = radians(lon2 - lon1) lat1 = radians(lat1) lat2 = radians(lat2) a = sin(dLat / 2)**2 + cos(lat1) * cos(lat2) * sin(dLon / 2)**2 c = 2 * asin(sqrt(a)) ...
Produce a functionally identical VB code for the snippet given in Elixir.
defmodule Haversine do @v :math.pi / 180 @r 6372.8 def distance({lat1, long1}, {lat2, long2}) do dlat = :math.sin((lat2 - lat1) * @v / 2) dlong = :math.sin((long2 - long1) * @v / 2) a = dlat * dlat + dlong * dlong * :math.cos(lat1 * @v) * :math.cos(lat2 * @v) @r * 2 * :math.asin(:ma...
Const MER = 6371 Public DEG_TO_RAD As Double Function haversine(lat1 As Double, long1 As Double, lat2 As Double, long2 As Double) As Double lat1 = lat1 * DEG_TO_RAD lat2 = lat2 * DEG_TO_RAD long1 = long1 * DEG_TO_RAD long2 = long2 * DEG_TO_RAD haversine = MER * WorksheetFunction.Acos(Sin(...
Write the same algorithm in VB as shown in this Elixir implementation.
defmodule Haversine do @v :math.pi / 180 @r 6372.8 def distance({lat1, long1}, {lat2, long2}) do dlat = :math.sin((lat2 - lat1) * @v / 2) dlong = :math.sin((long2 - long1) * @v / 2) a = dlat * dlat + dlong * dlong * :math.cos(lat1 * @v) * :math.cos(lat2 * @v) @r * 2 * :math.asin(:ma...
Const MER = 6371 Public DEG_TO_RAD As Double Function haversine(lat1 As Double, long1 As Double, lat2 As Double, long2 As Double) As Double lat1 = lat1 * DEG_TO_RAD lat2 = lat2 * DEG_TO_RAD long1 = long1 * DEG_TO_RAD long2 = long2 * DEG_TO_RAD haversine = MER * WorksheetFunction.Acos(Sin(...
Generate a Go translation of this Elixir snippet without changing its computational steps.
defmodule Haversine do @v :math.pi / 180 @r 6372.8 def distance({lat1, long1}, {lat2, long2}) do dlat = :math.sin((lat2 - lat1) * @v / 2) dlong = :math.sin((long2 - long1) * @v / 2) a = dlat * dlat + dlong * dlong * :math.cos(lat1 * @v) * :math.cos(lat2 * @v) @r * 2 * :math.asin(:ma...
package main import ( "fmt" "math" ) func haversine(θ float64) float64 { return .5 * (1 - math.Cos(θ)) } type pos struct { φ float64 ψ float64 } func degPos(lat, lon float64) pos { return pos{lat * math.Pi / 180, lon * math.Pi / 180} } const rEarth = 6372.8 func hsDist(p1, p2 pos) float...
Please provide an equivalent version of this Elixir code in Go.
defmodule Haversine do @v :math.pi / 180 @r 6372.8 def distance({lat1, long1}, {lat2, long2}) do dlat = :math.sin((lat2 - lat1) * @v / 2) dlong = :math.sin((long2 - long1) * @v / 2) a = dlat * dlat + dlong * dlong * :math.cos(lat1 * @v) * :math.cos(lat2 * @v) @r * 2 * :math.asin(:ma...
package main import ( "fmt" "math" ) func haversine(θ float64) float64 { return .5 * (1 - math.Cos(θ)) } type pos struct { φ float64 ψ float64 } func degPos(lat, lon float64) pos { return pos{lat * math.Pi / 180, lon * math.Pi / 180} } const rEarth = 6372.8 func hsDist(p1, p2 pos) float...
Produce a functionally identical C code for the snippet given in Erlang.
-module(haversine). -export([main/0]). main() -> haversine(36.12, -86.67, 33.94, -118.40). haversine(Lat1, Long1, Lat2, Long2) -> V = math:pi()/180, R = 6372.8, Diff_Lat = (Lat2 - Lat1)*V , Diff_Long = (Long2 - Long1)*V, NLat = Lat1*V, NLong = Lat2*V, A = math:sin(D...
#include <stdio.h> #include <stdlib.h> #include <math.h> #define R 6371 #define TO_RAD (3.1415926536 / 180) double dist(double th1, double ph1, double th2, double ph2) { double dx, dy, dz; ph1 -= ph2; ph1 *= TO_RAD, th1 *= TO_RAD, th2 *= TO_RAD; dz = sin(th1) - sin(th2); dx = cos(ph1) * cos(th1) - cos(th2); dy ...
Maintain the same structure and functionality when rewriting this code in C.
-module(haversine). -export([main/0]). main() -> haversine(36.12, -86.67, 33.94, -118.40). haversine(Lat1, Long1, Lat2, Long2) -> V = math:pi()/180, R = 6372.8, Diff_Lat = (Lat2 - Lat1)*V , Diff_Long = (Long2 - Long1)*V, NLat = Lat1*V, NLong = Lat2*V, A = math:sin(D...
#include <stdio.h> #include <stdlib.h> #include <math.h> #define R 6371 #define TO_RAD (3.1415926536 / 180) double dist(double th1, double ph1, double th2, double ph2) { double dx, dy, dz; ph1 -= ph2; ph1 *= TO_RAD, th1 *= TO_RAD, th2 *= TO_RAD; dz = sin(th1) - sin(th2); dx = cos(ph1) * cos(th1) - cos(th2); dy ...
Can you help me rewrite this code in C# instead of Erlang, keeping it the same logically?
-module(haversine). -export([main/0]). main() -> haversine(36.12, -86.67, 33.94, -118.40). haversine(Lat1, Long1, Lat2, Long2) -> V = math:pi()/180, R = 6372.8, Diff_Lat = (Lat2 - Lat1)*V , Diff_Long = (Long2 - Long1)*V, NLat = Lat1*V, NLong = Lat2*V, A = math:sin(D...
public static class Haversine { public static double calculate(double lat1, double lon1, double lat2, double lon2) { var R = 6372.8; var dLat = toRadians(lat2 - lat1); var dLon = toRadians(lon2 - lon1); lat1 = toRadians(lat1); lat2 = toRadians(lat2); var a = Math.Sin(dLat / 2) * Math.Sin(...
Please provide an equivalent version of this Erlang code in C#.
-module(haversine). -export([main/0]). main() -> haversine(36.12, -86.67, 33.94, -118.40). haversine(Lat1, Long1, Lat2, Long2) -> V = math:pi()/180, R = 6372.8, Diff_Lat = (Lat2 - Lat1)*V , Diff_Long = (Long2 - Long1)*V, NLat = Lat1*V, NLong = Lat2*V, A = math:sin(D...
public static class Haversine { public static double calculate(double lat1, double lon1, double lat2, double lon2) { var R = 6372.8; var dLat = toRadians(lat2 - lat1); var dLon = toRadians(lon2 - lon1); lat1 = toRadians(lat1); lat2 = toRadians(lat2); var a = Math.Sin(dLat / 2) * Math.Sin(...
Preserve the algorithm and functionality while converting the code from Erlang to C++.
-module(haversine). -export([main/0]). main() -> haversine(36.12, -86.67, 33.94, -118.40). haversine(Lat1, Long1, Lat2, Long2) -> V = math:pi()/180, R = 6372.8, Diff_Lat = (Lat2 - Lat1)*V , Diff_Long = (Long2 - Long1)*V, NLat = Lat1*V, NLong = Lat2*V, A = math:sin(D...
#define _USE_MATH_DEFINES #include <math.h> #include <iostream> const static double EarthRadiusKm = 6372.8; inline double DegreeToRadian(double angle) { return M_PI * angle / 180.0; } class Coordinate { public: Coordinate(double latitude ,double longitude):myLatitude(latitude), myLongitude(longitude) {} double...
Write a version of this Erlang function in C++ with identical behavior.
-module(haversine). -export([main/0]). main() -> haversine(36.12, -86.67, 33.94, -118.40). haversine(Lat1, Long1, Lat2, Long2) -> V = math:pi()/180, R = 6372.8, Diff_Lat = (Lat2 - Lat1)*V , Diff_Long = (Long2 - Long1)*V, NLat = Lat1*V, NLong = Lat2*V, A = math:sin(D...
#define _USE_MATH_DEFINES #include <math.h> #include <iostream> const static double EarthRadiusKm = 6372.8; inline double DegreeToRadian(double angle) { return M_PI * angle / 180.0; } class Coordinate { public: Coordinate(double latitude ,double longitude):myLatitude(latitude), myLongitude(longitude) {} double...
Convert the following code from Erlang to Java, ensuring the logic remains intact.
-module(haversine). -export([main/0]). main() -> haversine(36.12, -86.67, 33.94, -118.40). haversine(Lat1, Long1, Lat2, Long2) -> V = math:pi()/180, R = 6372.8, Diff_Lat = (Lat2 - Lat1)*V , Diff_Long = (Long2 - Long1)*V, NLat = Lat1*V, NLong = Lat2*V, A = math:sin(D...
public class Haversine { public static final double R = 6372.8; public static double haversine(double lat1, double lon1, double lat2, double lon2) { lat1 = Math.toRadians(lat1); lat2 = Math.toRadians(lat2); double dLat = lat2 - lat1; double dLon = Math.toRadians(lon2 - lon1); ...
Rewrite this program in Java while keeping its functionality equivalent to the Erlang version.
-module(haversine). -export([main/0]). main() -> haversine(36.12, -86.67, 33.94, -118.40). haversine(Lat1, Long1, Lat2, Long2) -> V = math:pi()/180, R = 6372.8, Diff_Lat = (Lat2 - Lat1)*V , Diff_Long = (Long2 - Long1)*V, NLat = Lat1*V, NLong = Lat2*V, A = math:sin(D...
public class Haversine { public static final double R = 6372.8; public static double haversine(double lat1, double lon1, double lat2, double lon2) { lat1 = Math.toRadians(lat1); lat2 = Math.toRadians(lat2); double dLat = lat2 - lat1; double dLon = Math.toRadians(lon2 - lon1); ...