View Full Version : no result showing using with (math)
bpaulsen2000
12-14-2002, 06:36 PM
hi,
having problem with code, as follows:
<script language="Javascript">
<!--
var lon1=80.281567;
var lon2=97.218167;
var lat1=43.102683;
var lat2=44.674678;
with (math){
var d=2*asin(sqrt((sin((lat1-lat2)/2))^2 +
cos(lat1)*cos(lat2)*(sin((lon1-lon2)/2))^2));
document.write(d);
)
//-->
</script>
joeframbach
12-14-2002, 06:50 PM
math should be capitalized.
also, you are closing a bracket with a parenthesis
with(Math)
{
}
bpaulsen2000
12-14-2002, 07:04 PM
Hi,
thanks for catching typos--still have problem with output
which results in
NaN
whatever that is?!?
joeframbach
12-14-2002, 07:12 PM
im getting that too. i dont know why either:confused:
bpaulsen2000
12-14-2002, 07:36 PM
hi again,
yeah, strange stuff. here's another version with different
latitudes and longitudes:
<script language="Javascript">
<!--
var lon1=80.281567;
var lon2=79.726284;
var lat1=40.604424;
var lat2=37.347167;
with (Math){
var d=2*asin(sqrt((sin((lat1-lat2)/2))^2 + cos(lat1)*cos(lat2)*(sin((lon1-lon2)/2))^2));
document.write(d);
}
//-->
</script>
joeframbach
12-14-2002, 07:38 PM
what is it supposed to return?
bpaulsen2000
12-14-2002, 09:17 PM
hi,
just an integer (possibly floating point) representing distance
between two zip codes using the great circle calculation.
mordred
12-15-2002, 01:17 AM
Perhaps you're getting over the limit of floating point numbers? They are only defined for a limited range of numbers.
Furthermore, is the bitwise operation with ^ intended or did you mean to use that as a short-hand for Math.pow(), which doesn't lead to the same result?
bpaulsen2000
12-15-2002, 04:06 AM
hi guys,
went serverside for correct usage. wrong algorithm anyhow.
thx for looksees though.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.