Wednesday, May 20, 2009

Divide 0 by 0

Here's a simple algo to divide 0.0 by 0.0:

double a = 0.0 / 0.0;
double b = 1.0 / 0.0;
double c = 0.0 / 1.0;
double d = 1.0 / 1.0;
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);

Here are the results:

NaN
Infinity
0.0
1.0


Good reference: http://www.math.utah.edu/~pa/math/0by0.html

No comments:

Post a Comment

Thank you for your comment.