/****************************************************************************** * Compilation: javac NegativeZero.java * Execution: java NegativeZero * * In Java, x = 0.0 and y = -0.0 are two different representations of zero. * It is true that (x == y). But, (1/x == 1/y) is not true. * * % java Zero * no * ******************************************************************************/ public class NegativeZero { public static void main(String[] args) { double x = 0.0; double y = -0.0; StdOut.println("x = " + x); StdOut.println("y = " + y); StdOut.println("(x == y) is " + (x == y)); double a = 1.0 / x; double b = 1.0 / y; StdOut.println("1/x = " + a); StdOut.println("1/y = " + b); StdOut.println("(1/x == 1/y) is " + (a == b)); } }