Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / March 2006

Tip: Looking for answers? Try searching our database.

java natural exponential and 'Infinity'

Thread view: 
NoIdea - 22 Mar 2006 16:49 GMT
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.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.