• fpclassify() et al

    From Bonita Montero@3:633/10 to All on Fri Jul 24 13:49:48 2026
    I've developed fpclassify() and similar parts of the glibc.
    Mostly faster than the glibc, especially fpclassify() itself.

    #pragma once
    #include <limits>
    #include <concepts>
    #include <type_traits>
    #include <cstdint>
    #include <bit>
    #include <cmath>

    template<typename Fp>
    concept fp_classify_types =
    (sizeof( Fp ) == 8 && std::same_as<Fp, double> && std::numeric_limits<double>::is_iec559)
    || (sizeof( Fp ) == 4 && std::same_as<Fp, float> && std::numeric_limits<float>::is_iec559);

    template<fp_classify_types Fp>
    struct fp_classify
    {
    static constexpr int type( Fp v ) noexcept;
    static constexpr bool normal( Fp v ) noexcept;
    static constexpr bool subnormal( Fp v ) noexcept;
    static constexpr bool finite( Fp v ) noexcept;
    static constexpr bool inf( Fp v ) noexcept;
    static constexpr bool nan( Fp v ) noexcept;
    private:
    static constexpr bool Fp8 = sizeof( Fp ) == 8;
    using word = std::conditional_t<Fp8, uint64_t, uint32_t>;
    static constexpr unsigned
    MantBits = Fp8 ? 52 : 23,
    MaxExp = Fp8 ? 0x7FFu : 0xFFu;
    static constexpr word
    Sign = 1ull << (Fp8 ? 63 : 31),
    Exp = (word)MaxExp << MantBits,
    MinNormal = 1ull << MantBits,
    Mant = MinNormal - 1;
    };

    template<fp_classify_types Fp>
    constexpr int fp_classify<Fp>::type( Fp v ) noexcept
    {
    word bin = std::bit_cast<word>( v ) & ~Sign;
    if( bin - MinNormal < Exp - MinNormal ) [[likely]]
    return FP_NORMAL;
    unsigned exp = bin >> MantBits;
    bool nzMant = bin & Mant;
    int
    zroExpType = nzMant ? FP_SUBNORMAL : FP_ZERO,
    maxExpType = nzMant ? FP_NAN : FP_INFINITE;
    return exp ? maxExpType : zroExpType;
    }

    template<fp_classify_types Fp>
    constexpr bool fp_classify<Fp>::normal( Fp v ) noexcept
    {
    word bin = std::bit_cast<word>( v ) & ~Sign;
    return bin - MinNormal < Exp - MinNormal;
    }

    template<fp_classify_types Fp>
    constexpr bool fp_classify<Fp>::subnormal( Fp v ) noexcept
    {
    word bin = std::bit_cast<word>( v ) & ~Sign;
    return bin - 1u < MinNormal - 1u;
    }

    template<fp_classify_types Fp>
    constexpr bool fp_classify<Fp>::finite( Fp v ) noexcept
    {
    return (std::bit_cast<word>( v ) & ~Sign) < Exp;
    }

    template<fp_classify_types Fp>
    constexpr bool fp_classify<Fp>::inf( Fp v ) noexcept
    {
    return (std::bit_cast<word>( v ) & ~Sign) == Exp;
    }

    template<fp_classify_types Fp>
    constexpr bool fp_classify<Fp>::nan( Fp v ) noexcept
    {
    return (std::bit_cast<word>( v ) & ~Sign) > Exp;
    }

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From boltar@3:633/10 to All on Fri Jul 24 17:22:17 2026
    On Fri, 24 Jul 2026 13:49:48 +0200
    Bonita Montero <Bonita.Montero@gmail.com> wrote:
    I've developed fpclassify() and similar parts of the glibc.
    Mostly faster than the glibc, especially fpclassify() itself.

    Any alternative to glibc has to be linkable with C object code so
    re-write the below in C or assembler and then get back to us.


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Bonita Montero@3:633/10 to All on Fri Jul 24 19:28:49 2026
    Am 24.07.2026 um 19:22 schrieb boltar@capricaworld.com:

    On Fri, 24 Jul 2026 13:49:48 +0200

    Bonita Montero <Bonita.Montero@gmail.com> wrote:

    I've developed fpclassify() and similar parts of the glibc.
    Mostly faster than the glibc, especially fpclassify() itself.

    Any alternative to glibc has to be linkable with C object code so
    re-write the below in C or assembler and then get back to us.

    Idiot, this is a C++ group.


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From boltar@3:633/10 to All on Sun Jul 26 08:44:09 2026
    On Fri, 24 Jul 2026 19:28:49 +0200
    Bonita Montero <Bonita.Montero@gmail.com> gabbled:
    Am 24.07.2026 um 19:22 schrieb boltar@capricaworld.com:

    On Fri, 24 Jul 2026 13:49:48 +0200

    Bonita Montero <Bonita.Montero@gmail.com> wrote:

    I've developed fpclassify() and similar parts of the glibc.
    Mostly faster than the glibc, especially fpclassify() itself.

    Any alternative to glibc has to be linkable with C object code so
    re-write the below in C or assembler and then get back to us.

    Idiot, this is a C++ group.

    No shit, thanks for the heads up. Whats the point of re-writing glibc in C++?


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Bonita Montero@3:633/10 to All on Sun Jul 26 12:59:30 2026
    Am 26.07.2026 um 10:44 schrieb boltar@caprica.universe:

    No shit, thanks for the heads up.
    Whats the point of re-writing glibc in C++?

    Just for fun and because it's faster.



    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)