aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Positive 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 "Positive Infinity" Watch "Positive Infinity" New topic
Author

Positive Infinity

Terry McKee
Ranch Hand

Joined: Sep 29, 2000
Posts: 173
Why does the following code result in Positive Infinity?

public class Test
{
public static void main(String []args)
{
double d = -10.0 / -0.0;
if (d == Double.POSITIVE_INFINITY)
System.out.println("d = Positive Infinity");
if (d == Double.NEGATIVE_INFINITY)
System.out.println("d = Negative Infinity");
}

}
Sagar Sharma
Ranch Hand

Joined: Aug 31, 2000
Posts: 92
hi,
though you divide a neagative number by -0.0 the computation is done for the signs which result in a positive entity. However the numerical result is INFINITY and hence the result shows up.
Thanks .....Hope it helps!!
Sagar
Raghvendra Sharma
Ranch Hand

Joined: Oct 09, 2000
Posts: 82
Dear Terry,
The result is POSITIVE_INFINITY because you are trying with both negative numbers, mathematically, if in a division, both the numbers are negative the resutl is always positive. So the result is POSITIVE_INFINITY and nothing different.
Try the same with -/+ and +/- and you'll get NEGATIVE_INFINITY.

hope it helps
regards,
raghav..
Terry McKee
Ranch Hand

Joined: Sep 29, 2000
Posts: 173
Thanks for the help. I realize that dividing two negative numbers results in a positive. I just don't understand why Java makes a distinction between -0.0 and 0.0.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Positive Infinity