std::numeri...mits::digits(3)

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

✨ NAME ✨

std::numeric_limits::digits β€” std::numeric_limits::digits (yes, bestie, the name is literally the name). This is the page from the C++ Standard Libary manual, and we are about to understand it fr fr.

πŸŽ€ Synopsis πŸŽ€

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

The value of std::numeric_limits<T>::digits is the number of digits in base-radix that can be represented by the type T without change. Slay.

For integer types, this is the number of bits not counting the sign bit and the padding bits (if any). For floating-point types, this is the digits of the mantissa (for IEC 559/IEEE 754 implementations, this is the number of digits stored for the mantissa plus one, because the mantissa has an implicit leading 1 and binary point). Iconic behavior, honestly.

πŸ’… Standard specializations πŸ’…

Okay so here’s the list energy for the standard specializations: these are the values of std::numeric_limits<T>::digits for each T, assuming no padding bits.

  • /* non-specialized */ β€” 0
  • bool β€” 1
  • char β€” CHAR_BIT - std::numeric_limits<char>::is_signed
  • signed char β€” CHAR_BIT - 1
  • unsigned char β€” CHAR_BIT
  • wchar_t β€” CHAR_BIT * sizeof(wchar_t) - std::numeric_limits<wchar_t>::is_signed
  • char8_t (since C++20) β€” CHAR_BIT
  • char16_t (since C++11) β€” CHAR_BIT * sizeof(char16_t)
  • char32_t (since C++11) β€” CHAR_BIT * sizeof(char32_t)
  • short β€” CHAR_BIT * sizeof(short) - 1
  • unsigned short β€” CHAR_BIT * sizeof(short)
  • int β€” CHAR_BIT * sizeof(int) - 1
  • unsigned int β€” CHAR_BIT * sizeof(int)
  • long β€” CHAR_BIT * sizeof(long) - 1
  • unsigned long β€” CHAR_BIT * sizeof(long)
  • long long (since C++11) β€” CHAR_BIT * sizeof(long long) - 1
  • unsigned long long (since C++11) β€” CHAR_BIT * sizeof(long long)
  • float β€” FLT_MANT_DIG
  • double β€” DBL_MANT_DIG
  • long double β€” LDBL_MANT_DIG
The β€œassuming no padding bits” caveat is doing important main character work here, so don’t forget it.

πŸ‘€ See also πŸ‘€

  • radix β€” the radix or integer base used by the representation of the given type; [static] (public static member constant)
  • min_exponent β€” one more than the smallest negative power of the radix that is a valid normalized floating-point value; [static] (public static member constant)
  • max_exponent β€” one more than the largest integer power of the radix that is a valid finite floating-point value; [static] (public static member constant)

Source/version and date tea: this page comes from http://cppreference.com, dated 2024.06.10, and its footer name is std::numeri...mits::digits(3). Periodt, that’s the whole page, and you ate it up πŸ«ΆπŸ’–βœ¨

πŸ“¦ where this page comes from