From 3ace3e39c687ea2e7fea52f91d5f75ab4e32f2cd Mon Sep 17 00:00:00 2001 From: peter klausler Date: Fri, 3 Aug 2018 16:02:05 -0700 Subject: [PATCH] [flang] Rename some NaNs. Original-commit: flang-compiler/f18@34eac17ddc11e83991e80ffe4f4937382ce07674 Reviewed-on: https://github.com/flang-compiler/f18/pull/162 Tree-same-pre-rewrite: false --- flang/lib/evaluate/complex.h | 4 +++- flang/lib/evaluate/int-power.h | 2 +- flang/lib/evaluate/real.cc | 14 +++++++------- flang/lib/evaluate/real.h | 6 +++--- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/flang/lib/evaluate/complex.h b/flang/lib/evaluate/complex.h index a8d481e..ae6989d 100644 --- a/flang/lib/evaluate/complex.h +++ b/flang/lib/evaluate/complex.h @@ -78,7 +78,9 @@ public: return {re_.FlushDenormalToZero(), im_.FlushDenormalToZero()}; } - static constexpr Complex NaN() { return {Part::NaN(), Part::NaN()}; } + static constexpr Complex NotANumber() { + return {Part::NotANumber(), Part::NotANumber()}; + } std::string DumpHexadecimal() const; // TODO: (C)ABS once Real::HYPOT is done diff --git a/flang/lib/evaluate/int-power.h b/flang/lib/evaluate/int-power.h index 66a9ceb..6f8a574 100644 --- a/flang/lib/evaluate/int-power.h +++ b/flang/lib/evaluate/int-power.h @@ -28,7 +28,7 @@ ValueWithRealFlags IntPower( ValueWithRealFlags result; result.value = one; if (base.IsNotANumber()) { - result.value = REAL::NaN(); + result.value = REAL::NotANumber(); if (base.IsSignalingNaN()) { result.flags.set(RealFlag::InvalidArgument); } diff --git a/flang/lib/evaluate/real.cc b/flang/lib/evaluate/real.cc index 95c999a..49ce0fa 100644 --- a/flang/lib/evaluate/real.cc +++ b/flang/lib/evaluate/real.cc @@ -60,7 +60,7 @@ ValueWithRealFlags> Real::Add( const Real &y, Rounding rounding) const { ValueWithRealFlags result; if (IsNotANumber() || y.IsNotANumber()) { - result.value = NaN(); // NaN + x -> NaN + result.value = NotANumber(); // NaN + x -> NaN if (IsSignalingNaN() || y.IsSignalingNaN()) { result.flags.set(RealFlag::InvalidArgument); } @@ -73,7 +73,7 @@ ValueWithRealFlags> Real::Add( if (isNegative == yIsNegative) { result.value = *this; // +/-Inf + +/-Inf -> +/-Inf } else { - result.value = NaN(); // +/-Inf + -/+Inf -> NaN + result.value = NotANumber(); // +/-Inf + -/+Inf -> NaN result.flags.set(RealFlag::InvalidArgument); } } else { @@ -140,7 +140,7 @@ ValueWithRealFlags> Real::Multiply( const Real &y, Rounding rounding) const { ValueWithRealFlags result; if (IsNotANumber() || y.IsNotANumber()) { - result.value = NaN(); // NaN * x -> NaN + result.value = NotANumber(); // NaN * x -> NaN if (IsSignalingNaN() || y.IsSignalingNaN()) { result.flags.set(RealFlag::InvalidArgument); } @@ -148,7 +148,7 @@ ValueWithRealFlags> Real::Multiply( bool isNegative{IsNegative() != y.IsNegative()}; if (IsInfinite() || y.IsInfinite()) { if (IsZero() || y.IsZero()) { - result.value = NaN(); // 0 * Inf -> NaN + result.value = NotANumber(); // 0 * Inf -> NaN result.flags.set(RealFlag::InvalidArgument); } else { result.value = Infinity(isNegative); @@ -200,7 +200,7 @@ ValueWithRealFlags> Real::Divide( const Real &y, Rounding rounding) const { ValueWithRealFlags result; if (IsNotANumber() || y.IsNotANumber()) { - result.value = NaN(); // NaN / x -> NaN, x / NaN -> NaN + result.value = NotANumber(); // NaN / x -> NaN, x / NaN -> NaN if (IsSignalingNaN() || y.IsSignalingNaN()) { result.flags.set(RealFlag::InvalidArgument); } @@ -208,14 +208,14 @@ ValueWithRealFlags> Real::Divide( bool isNegative{IsNegative() != y.IsNegative()}; if (IsInfinite()) { if (y.IsInfinite()) { - result.value = NaN(); // Inf/Inf -> NaN + result.value = NotANumber(); // Inf/Inf -> NaN result.flags.set(RealFlag::InvalidArgument); } else { // Inf/x -> Inf, Inf/0 -> Inf result.value = Infinity(isNegative); } } else if (y.IsZero()) { if (IsZero()) { // 0/0 -> NaN - result.value = NaN(); + result.value = NotANumber(); result.flags.set(RealFlag::InvalidArgument); } else { // x/0 -> Inf, Inf/0 -> Inf result.value = Infinity(isNegative); diff --git a/flang/lib/evaluate/real.h b/flang/lib/evaluate/real.h index bb11403..50557b9 100644 --- a/flang/lib/evaluate/real.h +++ b/flang/lib/evaluate/real.h @@ -124,8 +124,8 @@ public: return *this; } - // TODO: Configurable NaN representations - static constexpr Real NaN() { + // TODO: Configurable NotANumber representations + static constexpr Real NotANumber() { return {Word{maxExponent} .SHIFTL(significandBits) .IBSET(significandBits - 1) @@ -310,7 +310,7 @@ private: } // Normalizes and marshals the fields of a floating-point number in place. - // The value is not a NaN, and a zero fraction means a zero value (i.e., + // The value is a number, and a zero fraction means a zero value (i.e., // a maximal exponent and zero fraction doesn't signify infinity, although // this member function will detect overflow and encode infinities). RealFlags Normalize(bool negative, std::uint64_t exponent, -- 2.7.4