std::numeri...ts::is_exact(3)

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

πŸ’… std::numeric_limits::is_exact(3)

okay so picture this: we're deep in the C++ Standard Libary man pages (yes that's literally how it's spelled up top, don't come for me πŸ™ˆ) and we're here to talk about one tiny little static member that answers a very important question: "bestie, does your number type keep it πŸ’― exact?"


✨ NAME ✨

std::numeric_limits::is_exact β€” literally just std::numeric_limits::is_exact, she's self-titled, main character energy πŸ‘‘


πŸŽ€ Synopsis πŸŽ€

static const bool is_exact;      (until C++11)
static constexpr bool is_exact;  (since C++11)

The way this works is so simple it's giving minimalist: the value of std::numeric_limits<T>::is_exact is true for all arithmetic types T that use exact representation. That's it. That's the whole vibe. ✨


🌸 Standard specializations 🌸

here's the full roll call, no skips, no cuts, everybody gets a line πŸ’–

  • /* non-specialized */ β€” false
  • bool β€” true
  • char β€” true
  • signed char β€” true
  • unsigned char β€” true
  • wchar_t β€” true
  • char8_t (since C++20) β€” true
  • char16_t (since C++11) β€” true
  • char32_t (since C++11) β€” true
  • short β€” true
  • unsigned short β€” true
  • int β€” true
  • unsigned int β€” true
  • long β€” true
  • unsigned long β€” true
  • long long (since C++11) β€” true
  • unsigned long long (since C++11) β€” true
  • float β€” false
  • double β€” false
  • long double β€” false

so the integers ate and left no crumbs, and the floating point girlies are sitting at false β€” that's the whole energy of this table 🫢


πŸ¦‹ Notes πŸ¦‹

okay real talk, here's the little caveat that lives in the footnotes: while all fundamental types T for which std::numeric_limits<T>::is_exact == true are integer types, a library may define exact types that are not integers β€” for example, a rational arithmetic type representing fractions. so like, exact β‰  automatically integer, iykyk 😌


πŸ’œ See also πŸ’œ

  • is_integer β€” identifies integer types β€” [static] (public static member constant)
  • is_signed β€” identifies signed types β€” [static] (public static member constant)
  • is_bounded β€” identifies types that represent a finite set of values β€” [static] (public static member constant)

πŸ’€ friendly reminder: everything above is descriptive, so don't go assuming an exact type is an integer just because every fundamental one happens to be. read the Notes section, bestie, it's there for a reason.

and that's the page!! source is http://cppreference.com, dated 2024.06.10, filed under std::numeric_limits::is_exact(3) β€” go off and check your types, mwah πŸ’…πŸŽ€βœ¨

πŸ“¦ where this page comes from