Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
whats wrong with this code?
Old 03-08-2008, 05:37 PM whats wrong with this code?
Novice Talker

Posts: 5
Name: Sean
Trades: 0
Hi,

I am trying to understand what I did wrong here. My function is found below.

This statement seems to yield a negative result when north1>north2 and east1>east2. How is this possible? Any help would be most appreciated!
((east2-east1)^2)+((north2-north1)^2)

When this expression is evaluted for further evaluation by the sqrt Math function, it returns a NaN (can't sqrt a negative number). It shouldn't be a negative number, unless I don't understand how javascript deals with statements.

function DISTANCE_CALC(north1,north2,east1,east2)
{
var north1=Number(north1);
var north2=Number(north2);
var east1=Number(east1);
var east2=Number(east2);
return Math.sqrt(((east2-east1)^2)+((north2-north1)^2));
}
sean2me is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-09-2008, 01:42 PM Re: whats wrong with this code?
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
http://developer.mozilla.org/en/docs...wise_Operators
http://developer.mozilla.org/en/docs...jects:Math:pow
logic ali is offline
Reply With Quote
View Public Profile
 
Old 03-09-2008, 02:25 PM Re: whats wrong with this code?
Novice Talker

Posts: 5
Name: Sean
Trades: 0
Thanks Ali!

I guess Javascript isn't really robust when it comes to math. Thanks for your input!

I suppose it has what I need though. Is there another scripting language that offers more calc power than Javascript? I am mainly interested in Triginometry for now, but may move onto simultaneous equation solving via matrix methods (have to relearn that).

thanks for your help!
sean2me is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to whats wrong with this code?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25558 seconds with 12 queries