Why do we require something like Float.Infinity
Ritu Kapoor
Ranch Hand
Posts: 102
Sandeep Chhabra
Ranch Hand
Posts: 340
posted 11 years ago
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
For example
Hope this would help..
Sandy
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 nonnumeric
situations, both double and float can take on values that are bit patterns that do not represent
numbers. Rather, these patterns represent nonnumeric values. The patterns are defined in the
Float and Double classes and may be referenced as follows (NaN stands for Not a Number):
Float.NaN
Float.NEGATIVE_INFINITY
Float.POSITIVE_INFINITY
Double.NaN
Double.NEGATIVE_INFINITY
Double.POSITIVE_INFINITY
For example
Hope this would help..
Sandy
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 newfangled bit or byte,<br />Could ease the hacker's weary plight?
anand phulwani
Ranch Hand
Posts: 242
posted 11 years ago
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 310055 73%, SCWCD 1.4 310081 78%, IBM DB2 9 Fundamentals 000730 62%
Happiness is not a goal ... it's a byproduct of a life well lived  Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/ThreadBoostfeature
