You are here

function earth_asin_safe in Location 7.3

Same name and namespace in other branches
  1. 5.3 earth.inc \earth_asin_safe()
  2. 6.3 earth.inc \earth_asin_safe()
  3. 7.5 earth.inc \earth_asin_safe()
  4. 7.4 earth.inc \earth_asin_safe()

This is a helper function to avoid errors when using the asin() PHP function.

asin is only real for values between -1 and 1. If a value outside that range is given it returns NAN (not a number), which we don't want to happen. So this just rounds values outside this range to -1 or 1 first.

This means that calculations done using this function with $x outside the range will not be accurate. The alternative though is getting NAN, which is an error and won't give accurate results anyway.

File

./earth.inc, line 241
Trigonometry for calculating geographical distances. All function arguments and return values measure distances in metres and angles in degrees. The ellipsoid model is from the WGS-84 datum. Ka-Ping Yee, 2003-08-11

Code

function earth_asin_safe($x) {
  return asin(max(-1, min($x, 1)));
}