/* From Fred J. Tydeman on the NCEG list 24-Feb-1997 */ /* * The Java API documentation says that a floating-point value will be * converted to a string with enough digits so that it can be distinguished * from all other floating-point values with different bit patterns, in * particular, the adjacent floating-point values. * * This program tests that requirement by printing the adjacent values * 1.0 and 1.0+eps. eps is about 2.220446e-16 * * -- Fred Tydeman, tydeman @ tybor.com */ class testprnt { public static void main(String args[]){ double one; double onep1; double eps; long li; one = 1.0; li = Double.doubleToLongBits(one); li++; /* add one to unit in last place to get to adjacent number */ onep1 = Double.longBitsToDouble(li); eps = onep1 - one; System.out.println("1 is " + Double.toString(one)); System.out.println("eps is " + Double.toString(eps)); System.out.println("1+eps is " + Double.toString(onep1)); System.out.println("Did the above line print '1' or '1.00000000000000022e0'?"); }/* main */ }/* class testprnt */