File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why do we require something like Float.Infinity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Why do we require something like Float.Infinity" Watch "Why do we require something like Float.Infinity" New topic

Why do we require something like Float.Infinity

Ritu Kapoor
Ranch Hand

Joined: Oct 03, 2004
Posts: 102
My question is that why do we require some like Float.INFINITY OR DOUBLE.INFINITY. When there is a fixed range of values that can be stored in float or doubles? Where actually the need of Float.INFINITY arises?

If it seems senseless then pls bear with me, I really want to know.
Sandeep Chhabra
Ranch Hand

Joined: Aug 28, 2005
Posts: 340
Hi ritu,

when you divide an integer with 0 you get an Airthmatic Exception
eg: int a=1/0;

but with float the case is different. when you divide a floating point value with 0 the result surly there, but it cannot be a float or double
thats actually infinity and thus the constants Float.NEGATIVE_INFINITY and Float.POSITIVE_INFINITY are required

Many mathematical operations can yield
results that have no expression in numbers (infinity, for example). To describe such non-numeric
situations, both double and float can take on values that are bit patterns that do not represent
numbers. Rather, these patterns represent non-numeric values. The patterns are defined in the
Float and Double classes and may be referenced as follows (NaN stands for Not a Number):

For example

Hope this would help..


Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?
anand phulwani
Ranch Hand

Joined: Sep 10, 2005
Posts: 242
Ritu, if u are appearing for the exam do remember a small point that there is no such thing as Double.INFINITY or Float.INFINITY,We only Have Double.NEGATIVE_INFINITY,Float.NEGATIVE_INFINITY,Double.POSITIVE_INFINITY,Float.POSITIVE_INFINITY

Thanks and Regards, Anand
SCJP 5.0 310-055 73%, SCWCD 1.4 310-081 78%, IBM DB2 9 Fundamentals 000-730 62%
Ritu Kapoor
Ranch Hand

Joined: Oct 03, 2004
Posts: 102
Thanx to both of you guys!
I agree. Here's the link:
subject: Why do we require something like Float.Infinity
It's not a secret anymore!