Skip to content

Commit 11d01a5

Browse files
klauslermemfrob
authored andcommitted
[flang] Rename some NaNs.
Original-commit: flang-compiler/f18@34eac17 Reviewed-on: flang-compiler/f18#162 Tree-same-pre-rewrite: false
1 parent 4acb9ce commit 11d01a5

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

flang/lib/evaluate/complex.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ template<typename REAL_TYPE> class Complex {
7878
return {re_.FlushDenormalToZero(), im_.FlushDenormalToZero()};
7979
}
8080

81-
static constexpr Complex NaN() { return {Part::NaN(), Part::NaN()}; }
81+
static constexpr Complex NotANumber() {
82+
return {Part::NotANumber(), Part::NotANumber()};
83+
}
8284

8385
std::string DumpHexadecimal() const;
8486
// TODO: (C)ABS once Real::HYPOT is done

flang/lib/evaluate/int-power.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ ValueWithRealFlags<REAL> IntPower(
2828
ValueWithRealFlags<REAL> result;
2929
result.value = one;
3030
if (base.IsNotANumber()) {
31-
result.value = REAL::NaN();
31+
result.value = REAL::NotANumber();
3232
if (base.IsSignalingNaN()) {
3333
result.flags.set(RealFlag::InvalidArgument);
3434
}

flang/lib/evaluate/real.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ ValueWithRealFlags<Real<W, P, IM>> Real<W, P, IM>::Add(
6060
const Real &y, Rounding rounding) const {
6161
ValueWithRealFlags<Real> result;
6262
if (IsNotANumber() || y.IsNotANumber()) {
63-
result.value = NaN(); // NaN + x -> NaN
63+
result.value = NotANumber(); // NaN + x -> NaN
6464
if (IsSignalingNaN() || y.IsSignalingNaN()) {
6565
result.flags.set(RealFlag::InvalidArgument);
6666
}
@@ -73,7 +73,7 @@ ValueWithRealFlags<Real<W, P, IM>> Real<W, P, IM>::Add(
7373
if (isNegative == yIsNegative) {
7474
result.value = *this; // +/-Inf + +/-Inf -> +/-Inf
7575
} else {
76-
result.value = NaN(); // +/-Inf + -/+Inf -> NaN
76+
result.value = NotANumber(); // +/-Inf + -/+Inf -> NaN
7777
result.flags.set(RealFlag::InvalidArgument);
7878
}
7979
} else {
@@ -140,15 +140,15 @@ ValueWithRealFlags<Real<W, P, IM>> Real<W, P, IM>::Multiply(
140140
const Real &y, Rounding rounding) const {
141141
ValueWithRealFlags<Real> result;
142142
if (IsNotANumber() || y.IsNotANumber()) {
143-
result.value = NaN(); // NaN * x -> NaN
143+
result.value = NotANumber(); // NaN * x -> NaN
144144
if (IsSignalingNaN() || y.IsSignalingNaN()) {
145145
result.flags.set(RealFlag::InvalidArgument);
146146
}
147147
} else {
148148
bool isNegative{IsNegative() != y.IsNegative()};
149149
if (IsInfinite() || y.IsInfinite()) {
150150
if (IsZero() || y.IsZero()) {
151-
result.value = NaN(); // 0 * Inf -> NaN
151+
result.value = NotANumber(); // 0 * Inf -> NaN
152152
result.flags.set(RealFlag::InvalidArgument);
153153
} else {
154154
result.value = Infinity(isNegative);
@@ -200,22 +200,22 @@ ValueWithRealFlags<Real<W, P, IM>> Real<W, P, IM>::Divide(
200200
const Real &y, Rounding rounding) const {
201201
ValueWithRealFlags<Real> result;
202202
if (IsNotANumber() || y.IsNotANumber()) {
203-
result.value = NaN(); // NaN / x -> NaN, x / NaN -> NaN
203+
result.value = NotANumber(); // NaN / x -> NaN, x / NaN -> NaN
204204
if (IsSignalingNaN() || y.IsSignalingNaN()) {
205205
result.flags.set(RealFlag::InvalidArgument);
206206
}
207207
} else {
208208
bool isNegative{IsNegative() != y.IsNegative()};
209209
if (IsInfinite()) {
210210
if (y.IsInfinite()) {
211-
result.value = NaN(); // Inf/Inf -> NaN
211+
result.value = NotANumber(); // Inf/Inf -> NaN
212212
result.flags.set(RealFlag::InvalidArgument);
213213
} else { // Inf/x -> Inf, Inf/0 -> Inf
214214
result.value = Infinity(isNegative);
215215
}
216216
} else if (y.IsZero()) {
217217
if (IsZero()) { // 0/0 -> NaN
218-
result.value = NaN();
218+
result.value = NotANumber();
219219
result.flags.set(RealFlag::InvalidArgument);
220220
} else { // x/0 -> Inf, Inf/0 -> Inf
221221
result.value = Infinity(isNegative);

flang/lib/evaluate/real.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ template<typename WORD, int PRECISION, bool IMPLICIT_MSB = true> class Real {
124124
return *this;
125125
}
126126

127-
// TODO: Configurable NaN representations
128-
static constexpr Real NaN() {
127+
// TODO: Configurable NotANumber representations
128+
static constexpr Real NotANumber() {
129129
return {Word{maxExponent}
130130
.SHIFTL(significandBits)
131131
.IBSET(significandBits - 1)
@@ -310,7 +310,7 @@ template<typename WORD, int PRECISION, bool IMPLICIT_MSB = true> class Real {
310310
}
311311

312312
// Normalizes and marshals the fields of a floating-point number in place.
313-
// The value is not a NaN, and a zero fraction means a zero value (i.e.,
313+
// The value is a number, and a zero fraction means a zero value (i.e.,
314314
// a maximal exponent and zero fraction doesn't signify infinity, although
315315
// this member function will detect overflow and encode infinities).
316316
RealFlags Normalize(bool negative, std::uint64_t exponent,

0 commit comments

Comments
 (0)