Fortran 90 IEEE Question

Thomas MacDonald uunet!ironwood.cray.com!tam
Thu Feb 9 17:00:50 PST 1995


I was just asked the following Fortran 90 question.  Fortran 90 defines
a NEAREST function.  Essentially:

	X = NEAREST(2.0, +1.0)

assigns the value that is the next representable after 2.0 in the positive
direction (cause 1.0 is apositive number).  Fortran 90 also has a number
HUGE that is the largest finite number.  The question was about the
following two statements:

	X = NEAREST(HUGE, +1.0)  ! is this +infinity?
	Y = NEAREST(X, +1.0)     ! is this NaN?

I said that, in my opinion, X should have the value infinity, but that I
thought Y should also be infinity.  Does anyone know about other Fortran
90 compiler behavior for the above example?  Also, any opinions about
what the values of X and Y should be?

Jim Thomas' FPCE document doesn't explicitly spell this out for the
"nextafter" function.  A reasonable reading says that

	x = nextafter(DBL_MAX, HUGE_VAL);

should return +INFINITY as the result.  However, it doesn't let you ask
the question about the number after infinity because `nextafter' doesn't
really work the same way NEAREST does.

Thanks in advance.

Tom MacDonald
tamacray.com
uunet!cray!tam



More information about the Numeric-interest mailing list