how do you test for an infinite result given by the Java Math.exp()
function?
i need to do something like :-
if (Math.exp(200) "is infinite" ) {
{do something}
}
i've tried enclosing "Infinity" in quotes but it seems to think I'm
treating it as a string. Anyone any ideas how to do this?
Thanks
Thomas Weidenfeller - 22 Mar 2006 17:07 GMT
> how do you test for an infinite result given by the Java Math.exp()
> function?
[quoted text clipped - 7 lines]
> i've tried enclosing "Infinity" in quotes but it seems to think I'm
> treating it as a string. Anyone any ideas how to do this?
Double.POSITIVE_INFINITY
Double.NEGATIVE_INFINITY
/Thomas

Signature
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
Oliver Wong - 22 Mar 2006 17:21 GMT
> how do you test for an infinite result given by the Java Math.exp()
> function?
[quoted text clipped - 7 lines]
> i've tried enclosing "Infinity" in quotes but it seems to think I'm
> treating it as a string. Anyone any ideas how to do this?
Thomas gave you the answer. I just wanted to clarify that whenever you
enclose something in double-quotes, Java will always treat that as a String.
If you enclose something in single-quotes, it will always be treated as a
char.
- Oliver
Patricia Shanahan - 22 Mar 2006 17:28 GMT
> how do you test for an infinite result given by the Java Math.exp()
> function?
[quoted text clipped - 9 lines]
>
> Thanks
if( Double.isInfinite(Math.exp(200)) )
Double has a lot of utility methods, so it is a good idea to check its
javadoc if you are stuck trying to do something about a double.
Patricia
Roedy Green - 22 Mar 2006 20:21 GMT
>if (Math.exp(200) "is infinite" ) {
> {do something}
>}
see http://mindprod.com/jgloss/floatingpoint.html#NAN
and
http://mindprod.com/jgloss/gotchas.html#NAN

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Chris Smith - 22 Mar 2006 21:24 GMT
> >if (Math.exp(200) "is infinite" ) {
> > {do something}
[quoted text clipped - 3 lines]
> and
> http://mindprod.com/jgloss/gotchas.html#NAN
Since this came up recently, you may want to clarify on that page that
dividing by zero does not result in NaN, unless the numerator is also
zero. Generally, it results in an infinity of the appropriate sign.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Roedy Green - 22 Mar 2006 22:21 GMT
>Since this came up recently, you may want to clarify on that page that
>dividing by zero does not result in NaN, unless the numerator is also
>zero. Generally, it results in an infinity of the appropriate sign.
done

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.