std::numeri...x_exponent10(3)

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

πŸ’– NAME πŸ’–

std::numeric_limits::max_exponent10 β€” std::numeric_limits::max_exponent10

okay so bestie, welcome to the C++ Standard Libary manual β€” yes, that’s the manual name, spelling and all πŸ’… β€” and today’s main character is std::numeric_limits::max_exponent10. It’s giving very specific floating-point limit energy, and we’re gonna understand it fr fr. πŸ¦‹


✨ Synopsis ✨

Here’s the signature tea β˜•:

static const int max_exponent10;      (until C++11)
static constexpr int max_exponent10;  (since C++11)

The value of std::numeric_limits<T>::max_exponent10 is the largest positive number n such that 10^n is a representable finite value of the floating-point type T. 🌸


πŸ‘‘ Standard specializations πŸ‘‘

For each T, here’s the value of std::numeric_limits<T>::max_exponent10 β€” no cap, this is the whole roster:

  • /* non-specialized */ β€” 0
  • bool β€” 0
  • 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 C++11) β€” 0
  • float β€” FLT_MAX_10_EXP
  • double β€” DBL_MAX_10_EXP
  • long double β€” LDBL_MAX_10_EXP
bestie, notice how all the non-specialized and integer-ish types are sitting at 0 β€” that’s not a typo, that’s literally the table. πŸ’…

πŸŽ€ Example πŸŽ€

Demonstrates the relationships of max_exponent, max_exponent10, and max() for the type float:

// Run this code

#include <iostream>
#include <limits>

int main()
{
    std::cout << "max() = " << std::numeric_limits<float>::max() << '\n'
              << "max_exponent10 = " << std::numeric_limits<float>::max_exponent10 << '\n'
              << std::hexfloat << '\n'
              << "max() = " << std::numeric_limits<float>::max() << '\n'
              << "max_exponent = " << std::numeric_limits<float>::max_exponent << '\n';
}

🌈 Output 🌈

max() = 3.40282e+38
max_exponent10 = 38

max() = 0x1.fffffep+127
max_exponent = 128

πŸ‘€ See also πŸ‘€

Go peek at these too, iykyk:

  • max_exponent [static] β€” one more than the largest integer power of the radix that is a valid finite floating-point value (public static member constant)
  • min_exponent [static] β€” one more than the smallest negative power of the radix that is a valid normalized floating-point value (public static member constant)
  • min_exponent10 [static] β€” the smallest negative power of ten that is a valid normalized floating-point value (public static member constant)

That’s the whole page, bestie 🫢 β€” source: http://cppreference.com, version/date: 2024.06.10. Slay and stay numeric πŸ’œβœ¨

πŸ“¦ where this page comes from