std::numeri...::denorm_min(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

okay so this is std::numeri...::denorm_min(3) from the C++ Standard Libary manual β€” yes, Libary, we're keeping the typo, it's iconic πŸ’…βœ¨

πŸ’– NAME πŸ’–

std::numeric_limits::denorm_min β€” aka std::numeric_limits::denorm_min, bestie. That's the name, and we are not changing it, no cap.

✨ Synopsis ✨

Two moods depending on your C++ era, fr fr:

static T denorm_min() throw();             (until C++11)
static constexpr T denorm_min() noexcept;  (since C++11)

Here's the tea πŸ«–: this returns the minimum positive subnormal value of type T if std::numeric_limits<T>::has_denorm != std::denorm_absent. If that's not the case, it returns std::numeric_limits<T>::min() for floating-point types and T() for all other types. It's only meaningful for floating-point types, so don't come for the non-float girlies expecting subnormal magic πŸ˜­πŸ’€

πŸŽ€ Return value πŸŽ€

Left side is T, right side is std::numeric_limits<T>::denorm_min() β€” here's the whole lineup, every single one πŸ‘‘:

  • /* non-specialized */ β†’ T()
  • bool β†’ false
  • char β†’ 0
  • signed char β†’ 0
  • unsigned char β†’ 0
  • wchar_t β†’ 0
  • char8_t (since C++20) β†’ 0
  • char16_t (since C++11) β†’ 0
  • char32_t (since C++11) β†’ 0
  • short β†’ 0
  • unsigned short β†’ 0
  • int β†’ 0
  • unsigned int β†’ 0
  • long β†’ 0
  • unsigned long β†’ 0
  • long long (since C++11) β†’ 0
  • unsigned long long since (since C++11) β†’ 0
  • float β†’ FLT_TRUE_MIN (\(\scriptsize 2^{-149}\)2-149 if std::numeric_limits<float>::is_iec559 is true)
  • double β†’ DBL_TRUE_MIN (\(\scriptsize 2^{-1074}\)2-1074 if std::numeric_limits<double>::is_iec559 is true)
  • long double β†’ LDBL_TRUE_MIN

πŸ¦‹ Example πŸ¦‹

This demo shows the underlying bit structure of denorm_min() and prints the values. Run this code, bestie:

        #include <cassert>
        #include <cstdint>
        #include <cstring>
        #include <iostream>
        #include <limits>

        int main()
        {
            // the smallest subnormal value has sign bit = 0, exponent = 0
            // and only the least significant bit of the fraction is 1
            std::uint32_t denorm_bits = 0x0001;
            float denorm_float;
            std::memcpy(&denorm_float, &denorm_bits, sizeof(float));

            assert(denorm_float == std::numeric_limits<float>::denorm_min());

            std::cout << "float\tmin()\t\tdenorm_min()\n";
            std::cout << "\t" << std::numeric_limits<float>::min() << '\t';
            std::cout <<         std::numeric_limits<float>::denorm_min() <<
       '\n';

            std::cout << "double\tmin()\t\tdenorm_min()\n";
            std::cout << "\t" << std::numeric_limits<double>::min() << '\t';
            std::cout <<         std::numeric_limits<double>::denorm_min() <<
       '\n';
        }

🎬 Possible output 🎬

        float   min()           denorm_min()
                1.17549e-38     1.4013e-45
        double  min()           denorm_min()
                2.22507e-308    4.94066e-324

🌸 See also 🌸

  • min β€” returns the smallest finite value of the given type [static] (public static member function)
  • has_denorm β€” identifies the denormalization style used by the floating-point type [static] (public static member constant)
  • lowest β€” returns the lowest finite value of the given type [static] (C++11) (public static member function)

That's the whole page, bestie 🫢 source: http://cppreference.com Β· date: 2024.06.10 Β· page: std::numeri...::denorm_min(3). Bye πŸ’…βœ¨

πŸ“¦ where this page comes from