std::numeric_limits::max(3)
π std::numeric_limits::max(3) π
okay so bestie, this page is from the C++ Standard Libary manual β yes, thatβs literally the manual name and weβre keeping the spelling, itβs iconic π
β and itβs all about std::numeric_limits::max. no cap, thatβs the whole main character here.
πΈ NAME πΈ
std::numeric_limits::max - std::numeric_limits::max
likeβ¦ itβs giving βthe function is the page and the page is the function,β fr fr.
β¨ Synopsis β¨
Defined in header <limits>:
static T max() throw(); (until C++11)
static constexpr T max() noexcept; (since C++11)
Returns the maximum finite value representable by the numeric type T. Meaningful for all bounded types. lowkey thatβs the whole vibe check: bounded types only, okay? π«Ά
π Return value π
Hereβs the full mapping, bestie β left side is T, right side is what std::numeric_limits<T>::max() gives you:
Tβstd::numeric_limits<T>::max()/* non-specialized */βT()boolβtruecharβCHAR_MAXsigned charβSCHAR_MAXunsigned charβUCHAR_MAXwchar_tβWCHAR_MAXchar8_t(since C++20) βUCHAR_MAXchar16_t(since C++11) βUINT_LEAST16_MAXchar32_t(since C++11) βUINT_LEAST32_MAXshortβSHRT_MAXunsigned shortβUSHRT_MAXintβINT_MAXunsigned intβUINT_MAXlongβLONG_MAXunsigned longβULONG_MAXlong long(since C++11) βLLONG_MAXunsigned long long(since C++11) βULLONG_MAXfloatβFLT_MAXdoubleβDBL_MAXlong doubleβLDBL_MAX
no skipped rows, no βwhateverβ energy β every single one is here π
π¦ Example π¦
Demonstrates the use of max() with some fundamental types and some standard library typedefs (the output is system-specific):
// Run this code
#include <cstddef>
#include <iostream>
#include <limits>
#include <string_view>
#include <type_traits>
template<typename T>
void print_max_twice(std::string_view type)
{
constexpr T max_value {std::numeric_limits<T>::max()};
std::cout << type << ": ";
if constexpr (std::is_floating_point_v<T>)
std::cout << std::defaultfloat << max_value << " or "
<< std::hexfloat << max_value << '\n';
else
std::cout << std::dec << static_cast<unsigned long long>(max_value) << " or "
<< std::hex << static_cast<unsigned long long>(max_value) << '\n';
}
int main()
{
std::cout << std::showbase;
print_max_twice<bool>("bool");
print_max_twice<short>("short");
print_max_twice<int>("int");
print_max_twice<std::streamsize>("streamsize");
print_max_twice<std::size_t>("size_t");
print_max_twice<char>("char");
print_max_twice<char16_t>("char16_t");
print_max_twice<wchar_t>("wchar_t");
print_max_twice<float>("float");
print_max_twice<double>("double");
print_max_twice<long double>("long double");
}
π Possible output π
bool: 1 or 0x1
short: 32767 or 0x7fff
int: 2147483647 or 0x7fffffff
streamsize: 9223372036854775807 or 0x7fffffffffffffff
size_t: 18446744073709551615 or 0xffffffffffffffff
char: 127 or 0x7f
char16_t: 65535 or 0xffff
wchar_t: 2147483647 or 0x7fffffff
float: 3.40282e+38 or 0x1.fffffep+127
double: 1.79769e+308 or 0x1.fffffffffffffp+1023
long double: 1.18973e+4932 or 0xf.fffffffffffffffp+16380
itβs giving βnumbers but make it hexadecimal too,β and honestly? obsessed π₯
π See also π
lowestβ returns the lowest finite value of the given type;[static](C++11)(public static member function)minβ returns the smallest finite value of the given type;[static](public static member function)
signed off from source/version http://cppreference.com on 2024.06.10, for page std::numeric_limits::max(3) β okay bye bestie, go max out those bounded types π
β¨π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms