# How to make a number not infinite

• 10-11-2012, 12:29 AM
Daryn
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
Code:

`r = Math.sqrt(totalPoints*xTotalSquared-Math.pow(xTotal,2);`
So after some trouble shooting i have found for a fact that my problem is the Math.sqrt.It returns a infinite number so I get nan instead of the Answer. Would any of you happen to know how to make my answer go from infinite to terminating.Please help right away i need to do my homework.
• 10-11-2012, 04:00 AM
pbrockway2
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.
• 10-11-2012, 04:08 AM
Daryn
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
• 10-11-2012, 04:35 AM
pbrockway2
Re: How to make a number not infinite
You're welcome.
• 10-11-2012, 09:27 AM
JosAH
Re: How to make a number not infinite
Quote:

Originally Posted by Daryn
Code:

`r = Math.sqrt(totalPoints*xTotalSquared-Math.pow(xTotal,2);`
So after some trouble shooting i have found for a fact that my problem is the Math.sqrt.It returns a infinite number so I get nan instead of the Answer. Would any of you happen to know how to make my answer go from infinite to terminating.Please help right away i need to do my homework.

I think I don't understand your question; Math.sqrt(x) return infinite if and only if x (the argument) is infinite; and where does the NaN come from?

kind regards,

Jos
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "http://www.java-forums.org/new-java/63764-how-make-number-not-infinite-print.html", "fetch_time": 1481279784000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2016-50/segments/1480698542693.41/warc/CC-MAIN-20161202170902-00280-ip-10-31-129-80.ec2.internal.warc.gz", "warc_record_offset": 535408579, "warc_record_length": 3364, "token_count": 732, "char_count": 2928, "score": 3.90625, "int_score": 4, "crawl": "CC-MAIN-2016-50", "snapshot_type": "latest", "language": "en", "language_score": 0.8969818949699402, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00008-of-00064.parquet"}