std::numeri...max_exponent(3)

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

πŸ’– NAME πŸ’–

okay bestie, welcome to the std::numeri...max_exponent(3) page β€” the main character is std::numeric_limits::max_exponent, from the C++ Standard Library. The NAME section is literally std::numeric_limits::max_exponent β€” std::numeric_limits::max_exponent (yes, it repeats, that’s the bit).


✨ Synopsis ✨

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

The value of std::numeric_limits<T>::max_exponent is the largest positive number n such that r^(n-1) β€” where r is std::numeric_limits<T>::radix β€” is a representable finite value of the floating-point type T. That’s the whole vibe: it’s the biggest positive n that still works out to a finite representable floating-point value, no cap.


🫢 Standard specializations 🫢

Here’s the value of std::numeric_limits<T>::max_exponent for each standard specialization:

  • /* 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_EXP
  • double β€” DBL_MAX_EXP
  • long double β€” LDBL_MAX_EXP

πŸ’… Example πŸ’…

This one demonstrates the relationships of max_exponent, max_exponent10, and max() for the type float. The page drops a // Run this code marker, then:

#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 🌈

  • min_exponent10 β€” [static] the smallest negative power of ten that is a valid normalized 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).
  • max_exponent10 β€” [static] the largest integer power of 10 that is a valid finite floating-point value (public static member constant).

byeee bestie, this iconic little page came from http://cppreference.com and is dated 2024.06.10 β€” drink water, check your exponents, mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from