in reply to Check whether two numbers are within a range

This?

DB<54> $b=3.1565323 DB<55> $a=3.1566789 DB<56> p abs(1e5*($b-$a)) <1 DB<57> p abs(1e5*($b-$a)) 14.660000000033 DB<58>

of course you could avoid the multiplication by providing an accurate threshold smaller than 1.

It'll become more complicated with two coordinates, than I'd say Pythagoras is accurate enough°

edit

Pythagoras sqr( d_x ** 2 + d_y ** 2 ) with d_ for delta= abs(c0-c1)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

°) even for spherical coordinates of that size (but don't use this for the distance between New York and Seattle, you might fall off the edge of the world)

Replies are listed 'Best First'.
Re^2: Check whether two numbers are within a range
by stevieb (Canon) on Feb 26, 2021 at 16:56 UTC

    Thank you. This works well, regardless if the vehicle's actual location will be plus or minus the pre-determined coordinates I'll be comparing against.

    Mock up:

    use warnings; use strict; use feature 'say'; use constant { ACCURACY => 1e5, RANGE => 1.2, LON => -119.31665, }; my $lon_current = -119.31666; my $deviation = abs(ACCURACY * (LON - $lon_current)); say "Within range: $deviation" if $deviation < RANGE;
      I hope you are not only testing the longitude but also the latitude.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery