Pop-Up Thingie
Sidebar
d0p3 BBS
Home
Forum
Files
Dark
Register
Log in
Username
Password
Sidebar
Forum
Fidonet
COMP.LANG.C++
Fastest version of nextafter
From
Bonita Montero
@3:633/10 to
All
on Thu Aug 13 15:44:57 2026
Similar to nextafter, but much faster:
template<typename Fp>
template<bool Up>
constexpr Fp fp_tools<Fp>::next( Fp v ) noexcept
{
using namespace std;
constexpr Fp Min = numeric_limits<Fp>::denorm_min();
sword sBin = bit_cast<word>( v );
word uBin = sBin & ~Sign;
if( !uBin ) [[unlikely]]
return Up ? Min : -Min;
sword mxDiff = uBin - Exp;
if( mxDiff > 0 ) [[unlikely]]
return v;
bool toInf = Up ? sBin >= 0 : sBin < 0;
if( !mxDiff && toInf ) [[unlikely]]
return v;
sBin += toInf ? 1 : -1;
word exp = sBin & Exp;
if( exp == Exp || !exp ) [[unlikely]]
{
feraiseexcept( FE_INEXACT | (exp == Exp ? FE_OVERFLOW : FE_UNDERFLOW) );
errno = ERANGE;
return v;
}
return bit_cast<Fp>( sBin );
}
--- PyGate Linux v1.5.19
* Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
Who's Online
Recent Visitors
RufusT
Tue May 19 12:56:22 2026
from
Dallas, TX
via
RLogin
Guest
Tue May 26 22:56:58 2026
from
Melbourne
via
Telnet
Guest
Sun Jun 14 06:31:07 2026
from
Ny
via
Telnet
Frostydev
Mon Jul 13 05:56:46 2026
from
Maryland
via
Raw
System Info
Sysop:
Tetrazocine
Location:
Melbourne, VIC, Australia
Users:
10
Nodes:
8 (
0
/
8
)
Uptime:
239:00:21
Calls:
220
Files:
21,513
Messages:
83,727