PROGRAM APPROX ************************************************************************ * Program to show inexact representation of reals by showing that for * * some real values X, X * (1.0 / X) is not equal to 1. Variables used * * are: * * X : a real number entered by the user * * Y : X * (1.0 / X) * * * * Input: X * * Output: The value of X, the value of Y = X * (1.0 / X), and a * * message indicated whether Y is equal to 1 * ************************************************************************ REAL X, Y * Get an arbitrary nonzero real number X PRINT *, 'ENTER NONZERO REAL NUMBER' READ *, X * Calculate product of X and 1/X, display it and difference * between it and 1 Y = X * (1.0 / X) PRINT *, 'X = ', X, ' Y = X * (1 / X) = ', Y PRINT *, '1.0 - Y = ', 1.0 - Y * Check if product is 1 and display appropriate message IF (Y .EQ. 1.0) THEN PRINT *, 'Y EQUALS 1' ELSE PRINT *, 'DUE TO ROUNDOFF ERROR, Y DOES NOT EQUAL 1' END IF END