🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c++
Article #798

A branch-free fpclassify()

#798
From: Bonita Montero
Date: Mon, 09 Nov 2026 07:41
27 lines
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;
}
Technical Details
Message-ID: <11crtee$11mqb$1@raubtier-asyl.eternal-september.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita Montero <Bonita.Montero@gmail.com>
Newsgroups: comp.lang.c++
Subject: A branch-free fpclassify()
Date: Mon, 9 Nov 2026 08:41:02 +0100
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <11crtee$11mqb$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 09 Nov 2026 07:41:03 +0000 (UTC)
Injection-Info: raubtier-asyl.eternal-september.org;
	logging-data="1104715"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+tk7p1WcT/dTN8vMLDyGSGlYuL7Ur6I8M="; posting-host="979cd523e6652580c764e240ac10b15c"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:kMT2E/O2qzDEZbI9jEY1reiBoR0= sha256:2HZtcGZP3fX70Sqx9JcxGAGrbOb7WVObCbMaZFSc2gc=
	sha1:K2Cz4tLwmzxHfiAmCEPfM4PUmzY= sha256:ID6QypIJptXHJihufRghaqUwA+GWqVTk24/AnLs3hR0=
Content-Language: de-DE