llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[Flang] FRACTION of +/- Inf, REAL and DOUBLE PRECISION, returns NaN instead of +/- Inf

Open chandankds opened this issue 2 years ago • 2 comments

The intrinsic FRACTION should return Inf, not NaN, for Inf argument.

The Intel compiler returns Inf, GNU returns NaN.

Program test_fraction_inf
  Real :: x
  Real(Kind(1.d0)) :: y
  x = Huge(x) ;  y = Huge(y)
  Call s(x,y)
Contains
  Subroutine s(x,y)
    Real :: x
    Real(Kind(1.d0)) :: y
    x = x + x; y = y + y
    Print *, x,y  ! expected Inf
    Print *, Fraction(x), Fraction(y) ! expected Inf
    x = -x ; y = -y
    Print *, Fraction(x), Fraction(y) ! expected Inf
  End Subroutine s
End Program Test_fraction_inf

chandankds avatar Dec 24 '23 09:12 chandankds

It might be prudent to check the Fortran standard. 16.9.90 FRACTION (X) ... If X is an IEEE infinity, the result is an IEEE NaN.

kargl avatar Dec 25 '23 03:12 kargl

Working as intended; closing bug.

klausler avatar Dec 25 '23 20:12 klausler