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

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

πŸ¦‹ std::numeric_limits::infinity πŸ¦‹

okay so this page is from the C++ Standard Libary manual β€” yep, that exact manual name is in the header, no cap β€” and it’s all about std::numeric_limits::infinity. It’s giving very niche but very iconic C++ energy. πŸ’…


🌸 NAME 🌸

std::numeric_limits::infinity β€” std::numeric_limits::infinity. Yes bestie, the name is literally the same thing twice; the manual page said what it said and I respect it.

✨ Synopsis ✨

static T infinity() throw();             (until C++11)
static constexpr T infinity() noexcept;  (since C++11)

So this returns the special value "positive infinity", as represented by the floating-point type T. It’s only meaningful if std::numeric_limits<T>::has_infinity == true. In IEEE 754 β€” the most common binary representation of floating-point numbers β€” the positive infinity is the value with all bits of the exponent set and all bits of the fraction cleared. Slay, bit patterns. πŸ”₯

πŸ’– Return value πŸ’–

Here’s the exact return-value map, every single row, no skipping, periodt:

  • T β€” std::numeric_limits<T>::infinity()
  • /* non-specialized */ β€” T()
  • bool β€” false
  • 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 β€” HUGE_VALF
  • double β€” HUGE_VAL
  • long double β€” HUGE_VALL

πŸŽ€ Example πŸŽ€

// Run this code

#include <iostream>
#include <limits>

int main()
{
    double max = std::numeric_limits<double>::max();
    double inf = std::numeric_limits<double>::infinity();

    if (inf > max)
        std::cout << inf << " is greater than " << max << '\n';
}

🌈 Output 🌈

inf is greater than 1.79769e+308

🫢 See also 🫢

  • has_infinity β€” identifies floating-point types that can represent the special value "positive infinity"; it’s marked [static] and is a public static member constant.

made with πŸ’– by your C++ group-chat bestie Β· source: cppreference.com Β· version/date: 2024.06.10 Β· and yes, std::numeric_limits::infinity ate, periodt πŸ§šβ€β™€οΈβœ¨

πŸ“¦ where this page comes from