Results 1 to 5 of 5
 10112012, 12:29 AM #1Senior Member
 Join Date
 Oct 2012
 Posts
 176
 Rep Power
 3
How to make a number not infinite
Alright so in my math class my teacher wants us to buy a 100 dollar Calculator inwich i cant offored. So I am now designing a calculator that will do everything I need the other one to do. Currently i am trying to find the correlation Coeffiecent everything works fine so fare except in the formula there is a line
Java Code:r = Math.sqrt(totalPoints*xTotalSquaredMath.pow(xTotal,2);
 10112012, 04:00 AM #2Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,708
 Rep Power
 13
Re: How to make a number not infinite
Generally NaN is considered a "feature".
Some mathematical expressions are syntactically correct, but make no sense in practice. For example you can use trigonometry to find the angles of a triangle given the sides. It's a nice expression, and all goes well until you substitute in the values 1  1  100 as the sides of the triangle: there simply is no such triangle or angles to be found in this case. The computing result in such cases is often NaN.
The best attitude, on encountering a NaN result, is not to wonder how to avoid it, but, rather, ask "why does this occur?", "am I calculating the right thing?", "am I calculating the right thing, but in an invalid context?".

According to the API docs Math.sqrt() will return NaN if you try to evaluate the square root of a negative number.
n*sigma(x^2)  sigma(x)^2 looks ok for the variance in one direction. Ie it's not obvious why the thing in the sqrt() should be negative if "total" means what it ought to mean. But, almost certainly, you are trying to find the square root of a negative quantity and the reason for that lies elsewhere in your code. Consider posting a SSCCE that shows the NaN occurring.
 10112012, 04:08 AM #3Senior Member
 Join Date
 Oct 2012
 Posts
 176
 Rep Power
 3
Re: How to make a number not infinite
Thanks you just help me solve it. It was because of the whole negative thing and i already know how to fix it thank you so much
 10112012, 04:35 AM #4Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,708
 Rep Power
 13
Re: How to make a number not infinite
You're welcome.
 10112012, 09:27 AM #5
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,044
 Blog Entries
 7
 Rep Power
 23
Re: How to make a number not infinite
The only person who got everything done by Friday was Robinson Crusoe.
Similar Threads

how to make grid number ?
By nikiiz in forum New To JavaReplies: 6Last Post: 05282012, 05:02 PM 
infinite loop
By javapink in forum New To JavaReplies: 19Last Post: 03062011, 03:28 AM 
how to end infinite loop
By search4survival in forum New To JavaReplies: 14Last Post: 10252010, 08:59 AM 
how do i make a string return a number?
By pjr5043 in forum New To JavaReplies: 6Last Post: 09152008, 04:56 AM 
Will make a pyramid of some kind out of a number
By romina in forum New To JavaReplies: 1Last Post: 08072007, 05:20 AM
Bookmarks