Skip to content

Commit 42160f6

Browse files
[llvm] APFloat: Query hasNanOrInf from semantics
1 parent e9aee4f commit 42160f6

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

llvm/include/llvm/ADT/APFloat.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ struct APFloatBase {
311311
static unsigned int semanticsIntSizeInBits(const fltSemantics&, bool);
312312
static bool semanticsHasZero(const fltSemantics &);
313313
static bool semanticsHasSignedRepr(const fltSemantics &);
314+
static bool semanticsHasInf(const fltSemantics &);
315+
static bool semanticsHasNan(const fltSemantics &);
314316

315317
// Returns true if any number described by \p Src can be precisely represented
316318
// by a normal (not subnormal) value in \p Dst.
@@ -1127,19 +1129,11 @@ class APFloat : public APFloatBase {
11271129
/// \param Semantics - type float semantics
11281130
static APFloat getAllOnesValue(const fltSemantics &Semantics);
11291131

1130-
/// Returns true if the given semantics supports either NaN or Infinity.
1132+
/// Returns true if the given semantics supports NaN or Infinity.
11311133
///
11321134
/// \param Sem - type float semantics
11331135
static bool hasNanOrInf(const fltSemantics &Sem) {
1134-
switch (SemanticsToEnum(Sem)) {
1135-
default:
1136-
return true;
1137-
// Below Semantics do not support {NaN or Inf}
1138-
case APFloat::S_Float6E3M2FN:
1139-
case APFloat::S_Float6E2M3FN:
1140-
case APFloat::S_Float4E2M1FN:
1141-
return false;
1142-
}
1136+
return semanticsHasNan(Sem) || semanticsHasInf(Sem);
11431137
}
11441138

11451139
/// Returns true if the given semantics has actual significand.

llvm/lib/Support/APFloat.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,15 @@ bool APFloatBase::semanticsHasSignedRepr(const fltSemantics &semantics) {
375375
return semantics.hasSignedRepr;
376376
}
377377

378+
bool APFloatBase::semanticsHasInf(const fltSemantics &semantics) {
379+
return semantics.nonFiniteBehavior != fltNonfiniteBehavior::NanOnly
380+
&& semantics.nonFiniteBehavior != fltNonfiniteBehavior::FiniteOnly;
381+
}
382+
383+
bool APFloatBase::semanticsHasNan(const fltSemantics &semantics) {
384+
return semantics.nonFiniteBehavior != fltNonfiniteBehavior::FiniteOnly;
385+
}
386+
378387
bool APFloatBase::isRepresentableAsNormalIn(const fltSemantics &Src,
379388
const fltSemantics &Dst) {
380389
// Exponent range must be larger.

0 commit comments

Comments
 (0)