[flang-commits] [PATCH] D151471: [flang] Retain the sign of the argument for the result of fraction(0)

vdonaldson via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu May 25 10:19:17 PDT 2023


vdonaldson created this revision.
vdonaldson added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert.
Herald added a project: All.
vdonaldson requested review of this revision.

The f18 clause 16.9.80 description of the FRACTION(X) intrinsic states:

  Result Value. The result has the value ....
  If X has the value zero, the result is zero.
  If X is an IEEE NaN, the result is that NaN.
  If X is an IEEE infinity, the result is an IEEE NaN.

This clause does not specify whether fraction(-0.0) should be -0.0 or +0.0.
However, a folded result and a runtime result should be consistent, and
returning -0.0 is more in line with the result for fraction(NaN).

For this test:

  print '(2f6.1)', 0.0, fraction(0.0)
  call f(0.0)
  print '(2f6.1)', -0.0, fraction(-0.0)
  call f(-0.0)
  end
  
  
  subroutine f(x)
    print '(2f6.1)', x, fraction(x)
  end

Current output is:

   0.0   0.0
   0.0   0.0
  -0.0  -0.0
  -0.0   0.0

Change that to:

   0.0   0.0
   0.0   0.0
  -0.0  -0.0
  -0.0  -0.0


https://reviews.llvm.org/D151471

Files:
  flang/runtime/numeric.cpp


Index: flang/runtime/numeric.cpp
===================================================================
--- flang/runtime/numeric.cpp
+++ flang/runtime/numeric.cpp
@@ -83,7 +83,7 @@
   } else if (std::isinf(x)) {
     return std::numeric_limits<T>::quiet_NaN(); // +/-Inf -> NaN
   } else if (x == 0) {
-    return 0; // 0 -> 0
+    return x; // 0 -> same 0
   } else {
     int ignoredExp;
     return std::frexp(x, &ignoredExp);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151471.525689.patch
Type: text/x-patch
Size: 428 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230525/8f1a1f70/attachment.bin>


More information about the flang-commits mailing list