Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Change the programming language of this snippet from Scala to C# without modifying what it does.
import java.lang.Math.* const val R = 6372.8 fun haversine(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double { val λ1 = toRadians(lat1) val λ2 = toRadians(lat2) val Δλ = toRadians(lat2 - lat1) val Δφ = toRadians(lon2 - lon1) return 2 * R * asin(sqrt(pow(sin(Δλ / 2), 2.0) + pow(sin(Δ...
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(...
Convert this Scala block to C++, preserving its control flow and logic.
import java.lang.Math.* const val R = 6372.8 fun haversine(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double { val λ1 = toRadians(lat1) val λ2 = toRadians(lat2) val Δλ = toRadians(lat2 - lat1) val Δφ = toRadians(lon2 - lon1) return 2 * R * asin(sqrt(pow(sin(Δλ / 2), 2.0) + pow(sin(Δ...
#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 Scala code.
import java.lang.Math.* const val R = 6372.8 fun haversine(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double { val λ1 = toRadians(lat1) val λ2 = toRadians(lat2) val Δλ = toRadians(lat2 - lat1) val Δφ = toRadians(lon2 - lon1) return 2 * R * asin(sqrt(pow(sin(Δλ / 2), 2.0) + pow(sin(Δ...
#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...
Keep all operations the same but rewrite the snippet in Java.
import java.lang.Math.* const val R = 6372.8 fun haversine(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double { val λ1 = toRadians(lat1) val λ2 = toRadians(lat2) val Δλ = toRadians(lat2 - lat1) val Δφ = toRadians(lon2 - lon1) return 2 * R * asin(sqrt(pow(sin(Δλ / 2), 2.0) + pow(sin(Δ...
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); ...
Keep all operations the same but rewrite the snippet in Java.
import java.lang.Math.* const val R = 6372.8 fun haversine(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double { val λ1 = toRadians(lat1) val λ2 = toRadians(lat2) val Δλ = toRadians(lat2 - lat1) val Δφ = toRadians(lon2 - lon1) return 2 * R * asin(sqrt(pow(sin(Δλ / 2), 2.0) + pow(sin(Δ...
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); ...
Port the following code from Scala to Python with equivalent syntax and logic.
import java.lang.Math.* const val R = 6372.8 fun haversine(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double { val λ1 = toRadians(lat1) val λ2 = toRadians(lat2) val Δλ = toRadians(lat2 - lat1) val Δφ = toRadians(lon2 - lon1) return 2 * R * asin(sqrt(pow(sin(Δλ / 2), 2.0) + pow(sin(Δ...
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 the following code from Scala to Python, ensuring the logic remains intact.
import java.lang.Math.* const val R = 6372.8 fun haversine(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double { val λ1 = toRadians(lat1) val λ2 = toRadians(lat2) val Δλ = toRadians(lat2 - lat1) val Δφ = toRadians(lon2 - lon1) return 2 * R * asin(sqrt(pow(sin(Δλ / 2), 2.0) + pow(sin(Δ...
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 Scala to VB with equivalent syntax and logic.
import java.lang.Math.* const val R = 6372.8 fun haversine(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double { val λ1 = toRadians(lat1) val λ2 = toRadians(lat2) val Δλ = toRadians(lat2 - lat1) val Δφ = toRadians(lon2 - lon1) return 2 * R * asin(sqrt(pow(sin(Δλ / 2), 2.0) + pow(sin(Δ...
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 language-to-language conversion: from Scala to VB, same semantics.
import java.lang.Math.* const val R = 6372.8 fun haversine(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double { val λ1 = toRadians(lat1) val λ2 = toRadians(lat2) val Δλ = toRadians(lat2 - lat1) val Δφ = toRadians(lon2 - lon1) return 2 * R * asin(sqrt(pow(sin(Δλ / 2), 2.0) + pow(sin(Δ...
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 Scala to Go with equivalent syntax and logic.
import java.lang.Math.* const val R = 6372.8 fun haversine(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double { val λ1 = toRadians(lat1) val λ2 = toRadians(lat2) val Δλ = toRadians(lat2 - lat1) val Δφ = toRadians(lon2 - lon1) return 2 * R * asin(sqrt(pow(sin(Δλ / 2), 2.0) + pow(sin(Δ...
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...
Write a version of this Scala function in Go with identical behavior.
import java.lang.Math.* const val R = 6372.8 fun haversine(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double { val λ1 = toRadians(lat1) val λ2 = toRadians(lat2) val Δλ = toRadians(lat2 - lat1) val Δφ = toRadians(lon2 - lon1) return 2 * R * asin(sqrt(pow(sin(Δλ / 2), 2.0) + pow(sin(Δ...
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 this program in C while keeping its functionality equivalent to the Swift version.
import Foundation func haversine(lat1:Double, lon1:Double, lat2:Double, lon2:Double) -> Double { let lat1rad = lat1 * Double.pi/180 let lon1rad = lon1 * Double.pi/180 let lat2rad = lat2 * Double.pi/180 let lon2rad = lon2 * Double.pi/180 let dLat = lat2rad - lat1rad let dLon = lon2rad - lon...
#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 ...
Port the provided Swift code into C while preserving the original functionality.
import Foundation func haversine(lat1:Double, lon1:Double, lat2:Double, lon2:Double) -> Double { let lat1rad = lat1 * Double.pi/180 let lon1rad = lon1 * Double.pi/180 let lat2rad = lat2 * Double.pi/180 let lon2rad = lon2 * Double.pi/180 let dLat = lat2rad - lat1rad let dLon = lon2rad - lon...
#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 a C# translation of this Swift snippet without changing its computational steps.
import Foundation func haversine(lat1:Double, lon1:Double, lat2:Double, lon2:Double) -> Double { let lat1rad = lat1 * Double.pi/180 let lon1rad = lon1 * Double.pi/180 let lat2rad = lat2 * Double.pi/180 let lon2rad = lon2 * Double.pi/180 let dLat = lat2rad - lat1rad let dLon = lon2rad - lon...
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 Swift code snippet into C# without altering its behavior.
import Foundation func haversine(lat1:Double, lon1:Double, lat2:Double, lon2:Double) -> Double { let lat1rad = lat1 * Double.pi/180 let lon1rad = lon1 * Double.pi/180 let lat2rad = lat2 * Double.pi/180 let lon2rad = lon2 * Double.pi/180 let dLat = lat2rad - lat1rad let dLon = lon2rad - lon...
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(...
Maintain the same structure and functionality when rewriting this code in C++.
import Foundation func haversine(lat1:Double, lon1:Double, lat2:Double, lon2:Double) -> Double { let lat1rad = lat1 * Double.pi/180 let lon1rad = lon1 * Double.pi/180 let lat2rad = lat2 * Double.pi/180 let lon2rad = lon2 * Double.pi/180 let dLat = lat2rad - lat1rad let dLon = lon2rad - lon...
#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 Swift code into C++ without altering its purpose.
import Foundation func haversine(lat1:Double, lon1:Double, lat2:Double, lon2:Double) -> Double { let lat1rad = lat1 * Double.pi/180 let lon1rad = lon1 * Double.pi/180 let lat2rad = lat2 * Double.pi/180 let lon2rad = lon2 * Double.pi/180 let dLat = lat2rad - lat1rad let dLon = lon2rad - lon...
#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 this program in Java while keeping its functionality equivalent to the Swift version.
import Foundation func haversine(lat1:Double, lon1:Double, lat2:Double, lon2:Double) -> Double { let lat1rad = lat1 * Double.pi/180 let lon1rad = lon1 * Double.pi/180 let lat2rad = lat2 * Double.pi/180 let lon2rad = lon2 * Double.pi/180 let dLat = lat2rad - lat1rad let dLon = lon2rad - lon...
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); ...
Port the following code from Swift to Java with equivalent syntax and logic.
import Foundation func haversine(lat1:Double, lon1:Double, lat2:Double, lon2:Double) -> Double { let lat1rad = lat1 * Double.pi/180 let lon1rad = lon1 * Double.pi/180 let lat2rad = lat2 * Double.pi/180 let lon2rad = lon2 * Double.pi/180 let dLat = lat2rad - lat1rad let dLon = lon2rad - lon...
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 functionally identical Python code for the snippet given in Swift.
import Foundation func haversine(lat1:Double, lon1:Double, lat2:Double, lon2:Double) -> Double { let lat1rad = lat1 * Double.pi/180 let lon1rad = lon1 * Double.pi/180 let lat2rad = lat2 * Double.pi/180 let lon2rad = lon2 * Double.pi/180 let dLat = lat2rad - lat1rad let dLon = lon2rad - lon...
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 Swift code into Python while preserving the original functionality.
import Foundation func haversine(lat1:Double, lon1:Double, lat2:Double, lon2:Double) -> Double { let lat1rad = lat1 * Double.pi/180 let lon1rad = lon1 * Double.pi/180 let lat2rad = lat2 * Double.pi/180 let lon2rad = lon2 * Double.pi/180 let dLat = lat2rad - lat1rad let dLon = lon2rad - lon...
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 Swift block to VB, preserving its control flow and logic.
import Foundation func haversine(lat1:Double, lon1:Double, lat2:Double, lon2:Double) -> Double { let lat1rad = lat1 * Double.pi/180 let lon1rad = lon1 * Double.pi/180 let lat2rad = lat2 * Double.pi/180 let lon2rad = lon2 * Double.pi/180 let dLat = lat2rad - lat1rad let dLon = lon2rad - lon...
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 provided Swift code into VB while preserving the original functionality.
import Foundation func haversine(lat1:Double, lon1:Double, lat2:Double, lon2:Double) -> Double { let lat1rad = lat1 * Double.pi/180 let lon1rad = lon1 * Double.pi/180 let lat2rad = lat2 * Double.pi/180 let lon2rad = lon2 * Double.pi/180 let dLat = lat2rad - lat1rad let dLon = lon2rad - lon...
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 Swift to Go, ensuring the logic remains intact.
import Foundation func haversine(lat1:Double, lon1:Double, lat2:Double, lon2:Double) -> Double { let lat1rad = lat1 * Double.pi/180 let lon1rad = lon1 * Double.pi/180 let lat2rad = lat2 * Double.pi/180 let lon2rad = lon2 * Double.pi/180 let dLat = lat2rad - lat1rad let dLon = lon2rad - lon...
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 Go instead of Swift, keeping it the same logically?
import Foundation func haversine(lat1:Double, lon1:Double, lat2:Double, lon2:Double) -> Double { let lat1rad = lat1 * Double.pi/180 let lon1rad = lon1 * Double.pi/180 let lat2rad = lat2 * Double.pi/180 let lon2rad = lon2 * Double.pi/180 let dLat = lat2rad - lat1rad let dLon = lon2rad - lon...
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 language-to-language conversion: from Tcl to C, same semantics.
package require Tcl 8.5 proc haversineFormula {lat1 lon1 lat2 lon2} { set rads [expr atan2(0,-1)/180] set R 6372.8 ; set dLat [expr {($lat2-$lat1) * $rads}] set dLon [expr {($lon2-$lon1) * $rads}] set lat1 [expr {$lat1 * $rads}] set lat2 [expr {$lat2 * $rads}] set a [expr {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 ...
Generate a C translation of this Tcl snippet without changing its computational steps.
package require Tcl 8.5 proc haversineFormula {lat1 lon1 lat2 lon2} { set rads [expr atan2(0,-1)/180] set R 6372.8 ; set dLat [expr {($lat2-$lat1) * $rads}] set dLon [expr {($lon2-$lon1) * $rads}] set lat1 [expr {$lat1 * $rads}] set lat2 [expr {$lat2 * $rads}] set a [expr {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 ...
Please provide an equivalent version of this Tcl code in C#.
package require Tcl 8.5 proc haversineFormula {lat1 lon1 lat2 lon2} { set rads [expr atan2(0,-1)/180] set R 6372.8 ; set dLat [expr {($lat2-$lat1) * $rads}] set dLon [expr {($lon2-$lon1) * $rads}] set lat1 [expr {$lat1 * $rads}] set lat2 [expr {$lat2 * $rads}] set a [expr {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(...
Preserve the algorithm and functionality while converting the code from Tcl to C#.
package require Tcl 8.5 proc haversineFormula {lat1 lon1 lat2 lon2} { set rads [expr atan2(0,-1)/180] set R 6372.8 ; set dLat [expr {($lat2-$lat1) * $rads}] set dLon [expr {($lon2-$lon1) * $rads}] set lat1 [expr {$lat1 * $rads}] set lat2 [expr {$lat2 * $rads}] set a [expr {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(...
Please provide an equivalent version of this Tcl code in C++.
package require Tcl 8.5 proc haversineFormula {lat1 lon1 lat2 lon2} { set rads [expr atan2(0,-1)/180] set R 6372.8 ; set dLat [expr {($lat2-$lat1) * $rads}] set dLon [expr {($lon2-$lon1) * $rads}] set lat1 [expr {$lat1 * $rads}] set lat2 [expr {$lat2 * $rads}] set a [expr {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...
Transform the following Tcl implementation into C++, maintaining the same output and logic.
package require Tcl 8.5 proc haversineFormula {lat1 lon1 lat2 lon2} { set rads [expr atan2(0,-1)/180] set R 6372.8 ; set dLat [expr {($lat2-$lat1) * $rads}] set dLon [expr {($lon2-$lon1) * $rads}] set lat1 [expr {$lat1 * $rads}] set lat2 [expr {$lat2 * $rads}] set a [expr {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 Tcl.
package require Tcl 8.5 proc haversineFormula {lat1 lon1 lat2 lon2} { set rads [expr atan2(0,-1)/180] set R 6372.8 ; set dLat [expr {($lat2-$lat1) * $rads}] set dLon [expr {($lon2-$lon1) * $rads}] set lat1 [expr {$lat1 * $rads}] set lat2 [expr {$lat2 * $rads}] set a [expr {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); ...
Translate this program into Java but keep the logic exactly as in Tcl.
package require Tcl 8.5 proc haversineFormula {lat1 lon1 lat2 lon2} { set rads [expr atan2(0,-1)/180] set R 6372.8 ; set dLat [expr {($lat2-$lat1) * $rads}] set dLon [expr {($lon2-$lon1) * $rads}] set lat1 [expr {$lat1 * $rads}] set lat2 [expr {$lat2 * $rads}] set a [expr {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 Tcl code into Python without altering its purpose.
package require Tcl 8.5 proc haversineFormula {lat1 lon1 lat2 lon2} { set rads [expr atan2(0,-1)/180] set R 6372.8 ; set dLat [expr {($lat2-$lat1) * $rads}] set dLon [expr {($lon2-$lon1) * $rads}] set lat1 [expr {$lat1 * $rads}] set lat2 [expr {$lat2 * $rads}] set a [expr {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)) ...
Write the same algorithm in Python as shown in this Tcl implementation.
package require Tcl 8.5 proc haversineFormula {lat1 lon1 lat2 lon2} { set rads [expr atan2(0,-1)/180] set R 6372.8 ; set dLat [expr {($lat2-$lat1) * $rads}] set dLon [expr {($lon2-$lon1) * $rads}] set lat1 [expr {$lat1 * $rads}] set lat2 [expr {$lat2 * $rads}] set a [expr {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)) ...
Rewrite this program in VB while keeping its functionality equivalent to the Tcl version.
package require Tcl 8.5 proc haversineFormula {lat1 lon1 lat2 lon2} { set rads [expr atan2(0,-1)/180] set R 6372.8 ; set dLat [expr {($lat2-$lat1) * $rads}] set dLon [expr {($lon2-$lon1) * $rads}] set lat1 [expr {$lat1 * $rads}] set lat2 [expr {$lat2 * $rads}] set a [expr {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(...
Keep all operations the same but rewrite the snippet in VB.
package require Tcl 8.5 proc haversineFormula {lat1 lon1 lat2 lon2} { set rads [expr atan2(0,-1)/180] set R 6372.8 ; set dLat [expr {($lat2-$lat1) * $rads}] set dLon [expr {($lon2-$lon1) * $rads}] set lat1 [expr {$lat1 * $rads}] set lat2 [expr {$lat2 * $rads}] set a [expr {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(...
Rewrite this program in Go while keeping its functionality equivalent to the Tcl version.
package require Tcl 8.5 proc haversineFormula {lat1 lon1 lat2 lon2} { set rads [expr atan2(0,-1)/180] set R 6372.8 ; set dLat [expr {($lat2-$lat1) * $rads}] set dLon [expr {($lon2-$lon1) * $rads}] set lat1 [expr {$lat1 * $rads}] set lat2 [expr {$lat2 * $rads}] set a [expr {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...
Generate an equivalent Go version of this Tcl code.
package require Tcl 8.5 proc haversineFormula {lat1 lon1 lat2 lon2} { set rads [expr atan2(0,-1)/180] set R 6372.8 ; set dLat [expr {($lat2-$lat1) * $rads}] set dLon [expr {($lon2-$lon1) * $rads}] set lat1 [expr {$lat1 * $rads}] set lat2 [expr {$lat2 * $rads}] set a [expr {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...
Change the programming language of this snippet from Rust to PHP without modifying what it does.
struct Point { lat: f64, lon: f64, } fn haversine(origin: Point, destination: Point) -> f64 { const R: f64 = 6372.8; let lat1 = origin.lat.to_radians(); let lat2 = destination.lat.to_radians(); let d_lat = lat2 - lat1; let d_lon = (destination.lon - origin.lon).to_radians(); let a = (...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Produce a functionally identical PHP code for the snippet given in Rust.
struct Point { lat: f64, lon: f64, } fn haversine(origin: Point, destination: Point) -> f64 { const R: f64 = 6372.8; let lat1 = origin.lat.to_radians(); let lat2 = destination.lat.to_radians(); let d_lat = lat2 - lat1; let d_lon = (destination.lon - origin.lon).to_radians(); let a = (...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Keep all operations the same but rewrite the snippet in PHP.
with Ada.Text_IO; use Ada.Text_IO; with Ada.Long_Float_Text_IO; use Ada.Long_Float_Text_IO; with Ada.Numerics.Generic_Elementary_Functions; procedure Haversine_Formula is package Math is new Ada.Numerics.Generic_Elementary_Functions (Long_Float); use Math; function Great_Circle_Distance (lat1, long1, lat2,...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Maintain the same structure and functionality when rewriting this code in PHP.
with Ada.Text_IO; use Ada.Text_IO; with Ada.Long_Float_Text_IO; use Ada.Long_Float_Text_IO; with Ada.Numerics.Generic_Elementary_Functions; procedure Haversine_Formula is package Math is new Ada.Numerics.Generic_Elementary_Functions (Long_Float); use Math; function Great_Circle_Distance (lat1, long1, lat2,...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Change the following Arturo code into PHP without altering its purpose.
radians: function [x]-> x * pi // 180 haversine: function [src,tgt][ dLat: radians tgt\0 - src\0 dLon: radians tgt\1 - src\1 lat1: radians src\0 lat2: radians tgt\0 a: add product @[cos lat1, cos lat2, sin dLon/2, sin dLon/2] (sin dLat/2) ^ 2 c: 2 * asin sqrt a return 6372.8 * c ] print h...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Translate the given Arturo code snippet into PHP without altering its behavior.
radians: function [x]-> x * pi // 180 haversine: function [src,tgt][ dLat: radians tgt\0 - src\0 dLon: radians tgt\1 - src\1 lat1: radians src\0 lat2: radians tgt\0 a: add product @[cos lat1, cos lat2, sin dLon/2, sin dLon/2] (sin dLat/2) ^ 2 c: 2 * asin sqrt a return 6372.8 * c ] print h...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Maintain the same structure and functionality when rewriting this code in PHP.
MsgBox, % GreatCircleDist(36.12, 33.94, -86.67, -118.40, 6372.8, "km") GreatCircleDist(La1, La2, Lo1, Lo2, R, U) { return, 2 * R * ASin(Sqrt(Hs(Rad(La2 - La1)) + Cos(Rad(La1)) * Cos(Rad(La2)) * Hs(Rad(Lo2 - Lo1)))) A_Space U } Hs(n) { return, (1 - Cos(n)) / 2 } Rad(Deg) { return, Deg * 4 * ATan(1) / 180 }
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Port the following code from AutoHotKey to PHP with equivalent syntax and logic.
MsgBox, % GreatCircleDist(36.12, 33.94, -86.67, -118.40, 6372.8, "km") GreatCircleDist(La1, La2, Lo1, Lo2, R, U) { return, 2 * R * ASin(Sqrt(Hs(Rad(La2 - La1)) + Cos(Rad(La1)) * Cos(Rad(La2)) * Hs(Rad(Lo2 - Lo1)))) A_Space U } Hs(n) { return, (1 - Cos(n)) / 2 } Rad(Deg) { return, Deg * 4 * ATan(1) / 180 }
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Transform the following AWK implementation into PHP, 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...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Port the provided AWK code into PHP while preserving the original functionality.
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...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Write the same algorithm in PHP as shown in this BBC_Basic implementation.
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...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Write the same algorithm in PHP as shown in this BBC_Basic implementation.
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...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Transform the following Clojure implementation into PHP, maintaining the same output 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)...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Convert this Clojure snippet to PHP and keep its semantics consistent.
(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)...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Translate the given Common_Lisp code snippet into PHP without altering its behavior.
(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 (* (...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Change the programming language of this snippet from Common_Lisp to PHP 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 (* (...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Translate the given D code snippet into PHP 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 * ...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Convert this D snippet to PHP and keep its semantics consistent.
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 * ...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Port the provided Delphi code into PHP 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); ...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Generate an equivalent PHP 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); ...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Write a version of this Elixir function in PHP 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...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Write a version of this Elixir function in PHP 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...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Translate the given Erlang code snippet into PHP without altering its 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...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Port the provided Erlang code into PHP while preserving the original functionality.
-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...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Please provide an equivalent version of this F# code in PHP.
open System [<Measure>] type deg [<Measure>] type rad [<Measure>] type km let haversine (θ: float<rad>) = 0.5 * (1.0 - Math.Cos(θ/1.0<rad>)) let radPerDeg = (Math.PI / 180.0) * 1.0<rad/deg> type pos(latitude: float<deg>, longitude: float<deg>) = member this.φ = latitude * radPerDeg member this.ψ = longitud...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Produce a language-to-language conversion: from F# to PHP, same semantics.
open System [<Measure>] type deg [<Measure>] type rad [<Measure>] type km let haversine (θ: float<rad>) = 0.5 * (1.0 - Math.Cos(θ/1.0<rad>)) let radPerDeg = (Math.PI / 180.0) * 1.0<rad/deg> type pos(latitude: float<deg>, longitude: float<deg>) = member this.φ = latitude * radPerDeg member this.ψ = longitud...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Port the provided Factor code into PHP while preserving the original functionality.
USING: arrays kernel math math.constants math.functions math.vectors sequences ; : haversin ( x -- y ) cos 1 swap - 2 / ; : haversininv ( y -- x ) 2 * 1 swap - acos ; : haversineDist ( as bs -- d ) [ [ 180 / pi * ] map ] bi@ [ [ swap - haversin ] 2map ] [ [ first cos ] bi@ * 1 swap 2array ] 2bi v. haversininv R_...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Translate the given Factor code snippet into PHP without altering its behavior.
USING: arrays kernel math math.constants math.functions math.vectors sequences ; : haversin ( x -- y ) cos 1 swap - 2 / ; : haversininv ( y -- x ) 2 * 1 swap - acos ; : haversineDist ( as bs -- d ) [ [ 180 / pi * ] map ] bi@ [ [ swap - haversin ] 2map ] [ [ first cos ] bi@ * 1 swap 2array ] 2bi v. haversininv R_...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Change the programming language of this snippet from Forth to PHP without modifying what it does.
: s>f s>d d>f ; : deg>rad 174532925199433e-16 f* ; : difference f- deg>rad 2 s>f f/ fsin fdup f* ; : haversine frot difference frot frot fover fover fswap difference fswap deg>rad fcos frot deg>rad fcos...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Rewrite the snippet below in PHP so it works the same as the original Forth code.
: s>f s>d d>f ; : deg>rad 174532925199433e-16 f* ; : difference f- deg>rad 2 s>f f/ fsin fdup f* ; : haversine frot difference frot frot fover fover fswap difference fswap deg>rad fcos frot deg>rad fcos...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Keep all operations the same but rewrite the snippet in PHP.
program example implicit none real :: d d = haversine(36.12,-86.67,33.94,-118.40) print '(A,F9.4,A)', 'distance: ',d,' km' contains function to_radian(degree) result(rad) real,intent(in) :: degree real, parameter :: deg_to_rad = atan(1.0)/45 real :: rad ra...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Change the programming language of this snippet from Fortran to PHP without modifying what it does.
program example implicit none real :: d d = haversine(36.12,-86.67,33.94,-118.40) print '(A,F9.4,A)', 'distance: ',d,' km' contains function to_radian(degree) result(rad) real,intent(in) :: degree real, parameter :: deg_to_rad = atan(1.0)/45 real :: rad ra...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Can you help me rewrite this code in PHP instead of Groovy, keeping it the same logically?
def haversine(lat1, lon1, lat2, lon2) { def R = 6372.8 def dLat = Math.toRadians(lat2 - lat1) def dLon = Math.toRadians(lon2 - lon1) lat1 = Math.toRadians(lat1) lat2 = Math.toRadians(lat2) def a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.c...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Write the same code in PHP as shown below in Groovy.
def haversine(lat1, lon1, lat2, lon2) { def R = 6372.8 def dLat = Math.toRadians(lat2 - lat1) def dLon = Math.toRadians(lon2 - lon1) lat1 = Math.toRadians(lat1) lat2 = Math.toRadians(lat2) def a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.c...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Write a version of this Haskell function in PHP with identical behavior.
import Control.Monad (join) import Data.Bifunctor (bimap) import Text.Printf (printf) haversine :: Float -> Float haversine = (^ 2) . sin . (/ 2) greatCircleDistance :: (Float, Float) -> (Float, Float) -> Float greatCircleDistance = distDeg 6371 where distDeg radius p1 p2 = distRad rad...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Keep all operations the same but rewrite the snippet in PHP.
import Control.Monad (join) import Data.Bifunctor (bimap) import Text.Printf (printf) haversine :: Float -> Float haversine = (^ 2) . sin . (/ 2) greatCircleDistance :: (Float, Float) -> (Float, Float) -> Float greatCircleDistance = distDeg 6371 where distDeg radius p1 p2 = distRad rad...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Write the same code in PHP as shown below in Icon.
link printf procedure main() printf("BNA to LAX is %d km (%d miles)\n", d := gcdistance([36.12, -86.67],[33.94, -118.40]),d*3280/5280) end procedure gcdistance(a,b) a[2] -:= b[2] every (x := a|b)[i := 1 to 2] := dtor(x[i]) dz := sin(a[1]) - sin(b[1]) dx := cos(a[2]) * cos(a[1]) - cos(b[1]) dy := s...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Transform the following Icon implementation into PHP, maintaining the same output and logic.
link printf procedure main() printf("BNA to LAX is %d km (%d miles)\n", d := gcdistance([36.12, -86.67],[33.94, -118.40]),d*3280/5280) end procedure gcdistance(a,b) a[2] -:= b[2] every (x := a|b)[i := 1 to 2] := dtor(x[i]) dz := sin(a[1]) - sin(b[1]) dx := cos(a[2]) * cos(a[1]) - cos(b[1]) dy := s...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Generate an equivalent PHP version of this J code.
require 'trig' haversin=: 0.5 * 1 - cos Rearth=: 6372.8 haversineDist=: Rearth * haversin^:_1@((1 , *&(cos@{.)) +/ .* [: haversin -)&rfd
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Port the provided J code into PHP while preserving the original functionality.
require 'trig' haversin=: 0.5 * 1 - cos Rearth=: 6372.8 haversineDist=: Rearth * haversin^:_1@((1 , *&(cos@{.)) +/ .* [: haversin -)&rfd
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Change the programming language of this snippet from Julia to PHP without modifying what it does.
haversine(lat1, lon1, lat2, lon2) = 2 * 6372.8 * asin(sqrt(sind((lat2 - lat1) / 2) ^ 2 + cosd(lat1) * cosd(lat2) * sind((lon2 - lon1) / 2) ^ 2)) @show haversine(36.12, -86.67, 33.94, -118.4)
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Transform the following Julia implementation into PHP, maintaining the same output and logic.
haversine(lat1, lon1, lat2, lon2) = 2 * 6372.8 * asin(sqrt(sind((lat2 - lat1) / 2) ^ 2 + cosd(lat1) * cosd(lat2) * sind((lon2 - lon1) / 2) ^ 2)) @show haversine(36.12, -86.67, 33.94, -118.4)
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Preserve the algorithm and functionality while converting the code from Lua to PHP.
local function haversine(x1, y1, x2, y2) r=0.017453292519943295769236907684886127; x1= x1*r; x2= x2*r; y1= y1*r; y2= y2*r; dy = y2-y1; dx = x2-x1; a = math.pow(math.sin(dx/2),2) + math.cos(x1) * math.cos(x2) * math.pow(math.sin(dy/2),2); c = 2 * math.asin(math.sqrt(a)); d = 6372.8 * c; return d; end
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Rewrite this program in PHP while keeping its functionality equivalent to the Lua version.
local function haversine(x1, y1, x2, y2) r=0.017453292519943295769236907684886127; x1= x1*r; x2= x2*r; y1= y1*r; y2= y2*r; dy = y2-y1; dx = x2-x1; a = math.pow(math.sin(dx/2),2) + math.cos(x1) * math.cos(x2) * math.pow(math.sin(dy/2),2); c = 2 * math.asin(math.sqrt(a)); d = 6372.8 * c; return d; end
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Port the following code from Mathematica to PHP with equivalent syntax and logic.
distance[{theta1_, phi1_}, {theta2_, phi2_}] := 2*6378.14 ArcSin@ Sqrt[Haversine[(theta2 - theta1) Degree] + Cos[theta1*Degree] Cos[theta2*Degree] Haversine[(phi2 - phi1) Degree]]
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Generate a PHP translation of this Mathematica snippet without changing its computational steps.
distance[{theta1_, phi1_}, {theta2_, phi2_}] := 2*6378.14 ArcSin@ Sqrt[Haversine[(theta2 - theta1) Degree] + Cos[theta1*Degree] Cos[theta2*Degree] Haversine[(phi2 - phi1) Degree]]
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Convert this MATLAB snippet to PHP and keep its semantics consistent.
function rad = radians(degree) rad = degree .* pi / 180; end; function [a,c,dlat,dlon]=haversine(lat1,lon1,lat2,lon2) 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 ...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Transform the following MATLAB implementation into PHP, maintaining the same output and logic.
function rad = radians(degree) rad = degree .* pi / 180; end; function [a,c,dlat,dlon]=haversine(lat1,lon1,lat2,lon2) 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 ...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Write the same code in PHP as shown below in Nim.
import std/math proc haversine(lat1, lon1, lat2, lon2: float): float = const r = 6372.8 let dLat = degToRad(lat2 - lat1) dLon = degToRad(lon2 - lon1) lat1 = degToRad(lat1) lat2 = degToRad(lat2) a = sin(dLat / 2) * sin(dLat / 2) + cos(lat1) * cos(lat2) * sin(dLon / 2) * sin(dLon / 2) c = 2...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Port the following code from Nim to PHP with equivalent syntax and logic.
import std/math proc haversine(lat1, lon1, lat2, lon2: float): float = const r = 6372.8 let dLat = degToRad(lat2 - lat1) dLon = degToRad(lon2 - lon1) lat1 = degToRad(lat1) lat2 = degToRad(lat2) a = sin(dLat / 2) * sin(dLat / 2) + cos(lat1) * cos(lat2) * sin(dLon / 2) * sin(dLon / 2) c = 2...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Write the same code in PHP as shown below in OCaml.
let pi = 4. *. atan 1. let radians_of_degrees = ( *. ) (pi /. 180.) let haversin theta = 0.5 *. (1. -. cos theta) type angle = Deg of float | Rad of float let as_radians = function | Deg d -> radians_of_degrees d | Rad r -> r module LatLong = struct type t = { lat: float; lng: float } let of_angles lat lng...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Generate an equivalent PHP version of this OCaml code.
let pi = 4. *. atan 1. let radians_of_degrees = ( *. ) (pi /. 180.) let haversin theta = 0.5 *. (1. -. cos theta) type angle = Deg of float | Rad of float let as_radians = function | Deg d -> radians_of_degrees d | Rad r -> r module LatLong = struct type t = { lat: float; lng: float } let of_angles lat lng...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Write the same code in PHP as shown below in Pascal.
program HaversineDemo; uses Math; function HaversineDistance(const lat1, lon1, lat2, lon2:double):double;inline; const rads = pi / 180; dia = 2 * 6372.8; begin HaversineDistance := dia * arcsin(sqrt(sqr(cos(rads * (lon1 - lon2)) * cos(rads * lat1) - cos(rads * lat2)) + sqr(sin(rads * ...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Convert this Pascal snippet to PHP and keep its semantics consistent.
program HaversineDemo; uses Math; function HaversineDistance(const lat1, lon1, lat2, lon2:double):double;inline; const rads = pi / 180; dia = 2 * 6372.8; begin HaversineDistance := dia * arcsin(sqrt(sqr(cos(rads * (lon1 - lon2)) * cos(rads * lat1) - cos(rads * lat2)) + sqr(sin(rads * ...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Write the same algorithm in PHP as shown in this Perl implementation.
use ntheory qw/Pi/; sub asin { my $x = shift; atan2($x, sqrt(1-$x*$x)); } sub surfacedist { my($lat1, $lon1, $lat2, $lon2) = @_; my $radius = 6372.8; my $radians = Pi() / 180;; my $dlat = ($lat2 - $lat1) * $radians; my $dlon = ($lon2 - $lon1) * $radians; $lat1 *= $radians; $lat2 *= $radians; my $a = s...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Rewrite this program in PHP while keeping its functionality equivalent to the Perl version.
use ntheory qw/Pi/; sub asin { my $x = shift; atan2($x, sqrt(1-$x*$x)); } sub surfacedist { my($lat1, $lon1, $lat2, $lon2) = @_; my $radius = 6372.8; my $radians = Pi() / 180;; my $dlat = ($lat2 - $lat1) * $radians; my $dlon = ($lon2 - $lon1) * $radians; $lat1 *= $radians; $lat2 *= $radians; my $a = s...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Generate a PHP translation of this PowerShell snippet without changing its computational steps.
Add-Type -AssemblyName System.Device $BNA = New-Object System.Device.Location.GeoCoordinate 36.12, -86.67 $LAX = New-Object System.Device.Location.GeoCoordinate 33.94, -118.40 $BNA.GetDistanceTo( $LAX ) / 1000
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Translate the given PowerShell code snippet into PHP without altering its behavior.
Add-Type -AssemblyName System.Device $BNA = New-Object System.Device.Location.GeoCoordinate 36.12, -86.67 $LAX = New-Object System.Device.Location.GeoCoordinate 33.94, -118.40 $BNA.GetDistanceTo( $LAX ) / 1000
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Produce a functionally identical PHP code for the snippet given in R.
dms_to_rad <- function(d, m, s) (d + m / 60 + s / 3600) * pi / 180 great_circle_distance <- function(lat1, long1, lat2, long2) { a <- sin(0.5 * (lat2 - lat1)) b <- sin(0.5 * (long2 - long1)) 12742 * asin(sqrt(a * a + cos(lat1) * cos(lat2) * b * b)) } great_circle_distance( dms_to_rad(36, 7, 28.10)...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Rewrite the snippet below in PHP so it works the same as the original R code.
dms_to_rad <- function(d, m, s) (d + m / 60 + s / 3600) * pi / 180 great_circle_distance <- function(lat1, long1, lat2, long2) { a <- sin(0.5 * (lat2 - lat1)) b <- sin(0.5 * (long2 - long1)) 12742 * asin(sqrt(a * a + cos(lat1) * cos(lat2) * b * b)) } great_circle_distance( dms_to_rad(36, 7, 28.10)...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...
Rewrite the snippet below in PHP so it works the same as the original Racket code.
#lang racket (require math) (define earth-radius 6371) (define (distance lat1 long1 lat2 long2) (define (h a b) (sqr (sin (/ (- b a) 2)))) (* 2 earth-radius (asin (sqrt (+ (h lat1 lat2) (* (cos lat1) (cos lat2) (h long1 long2))))))) (define (deg-to-rad d m s) (* (/ pi 180) (+ d (/ m ...
class POI { private $latitude; private $longitude; public function __construct($latitude, $longitude) { $this->latitude = deg2rad($latitude); $this->longitude = deg2rad($longitude); } public function getLatitude() { return $this->latitude; } public function getLong...