RosettaCodeData/Task/Haversine-formula/Factor/haversine-formula-1.factor
Ingy döt Net db842d013d A-M baby
2013-04-10 21:29:02 -07:00

11 lines
330 B
Factor

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_earth * ;