Thread View: comp.lang.c++
1 messages
1 total messages
Started by Bonita Montero
Mon, 09 Nov 2026 07:41
A branch-free fpclassify()
Author: Bonita Montero
Date: Mon, 09 Nov 2026 07:41
Date: Mon, 09 Nov 2026 07:41
27 lines
2077 bytes
2077 bytes
template<typename Fp>
constexpr int fp_type( Fp v ) noexcept
{
using namespace std;
static_assert( same_as<Fp, double> || same_as<Fp, float> );
static constexpr bool Dbl = std::same_as<Fp, double>;
using word = std::conditional_t<Dbl, uint64_t, uint32_t>;
static constexpr int
MantBits = Dbl ? 52 : 23,
MaxExp = Dbl ? 0x7FF : 0xFF;
static constexpr word
Sign = ~((word)-1 >> 1),
Exp = (word)MaxExp << MantBits,
MinNormal = (word)1 << MantBits,
Mant = MinNormal - 1;
word
bin = bit_cast<word>( v ),
exp = bin & Exp;
bool nzMant = (bin & Mant) != 0;
int
zroExpType = nzMant ? FP_SUBNORMAL : FP_ZERO,
maxExpType = nzMant ? FP_NAN : FP_INFINITE;
int type = exp != 0 ? maxExpType : zroExpType;
bool normal = bin - MinNormal < Exp - MinNormal;
type = normal ? FP_NORMAL : type;
return type;
}
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads