std::numeri...::quiet_NaN(3)

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

🌸 NAME 🌸

Okay bestie, welcome to the page for std::numeric_limits::quiet_NaN β€” the manual header calls it std::numeri...::quiet_NaN(3) and says it's from the C++ Standard Libary (their spelling, not mine πŸ’…). The NAME line is literally std::numeric_limits::quiet_NaN - std::numeric_limits::quiet_NaN, which is giving β€œI contain multitudes but also just my own name.” 🫢


πŸ¦‹ Synopsis πŸ¦‹

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

Returns the special value "quiet not-a-number", as represented by the floating-point type T. Only meaningful if std::numeric_limits<T>::has_quiet_NaN == true. In IEEE 754, the most common binary representation of floating-point numbers, any value with all bits of the exponent set and at least one bit of the fraction set represents a NaN. It is implementation-defined which values of the fraction represent quiet or signaling NaNs, and whether the sign bit is meaningful.


πŸ’– Return value πŸ’–

Here's the whole return-value roster, no gatekeeping, no skipped entries:

  • T β€” std::numeric_limits<T>::quiet_NaN()
  • /* 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 β€” implementation-defined (may be NAN)
  • double β€” implementation-defined
  • long double β€” implementation-defined

πŸŽ€ Notes πŸŽ€

Two little caveats with main-character energy:

  • A NaN never compares equal to itself.
  • Copying a NaN may not preserve its bit representation.

🌈 Example 🌈

Several ways to generate a NaN (the output string is compiler-specific). The page also has a literal // Run this code line right before the snippet, so here's the snippet:

#include <iostream>
#include <limits>
#include <cmath>

int main()
{
    std::cout << std::numeric_limits<double>::quiet_NaN()     << ' ' // nan
              << std::numeric_limits<double>::signaling_NaN() << ' ' // nan
              << std::acos(2)    << ' '   // nan
              << std::tgamma(-1) << ' '   // nan
              << std::log(-1)    << ' '   // nan
              << std::sqrt(-1)   << ' '   // -nan
              << 0 / 0.0         << '\n'; // -nan

    std::cout << "NaN == NaN? " << std::boolalpha
              << ( std::numeric_limits<double>::quiet_NaN() ==
                   std::numeric_limits<double>::quiet_NaN() ) << '\n';
}

⭐ Possible output ⭐

nan nan nan nan nan -nan -nan
NaN == NaN? false

πŸ‘‘ See also πŸ‘‘

  • has_quiet_NaN β€” identifies floating-point types that can represent the special value "quiet not-a-number" (NaN) [static] (public static member constant)
  • signaling_NaN β€” returns a signaling NaN value of the given floating-point type [static] (public static member function)
  • nan, nanf, nanl β€” not-a-number (NaN) (C++11) (function) (C++11) (C++11)
  • isnan β€” checks if the given number is NaN (C++11) (function)

Alright bestie, that's the whole page πŸ’– β€” source http://cppreference.com, date 2024.06.10, and the page is std::numeri...::quiet_NaN(3). Stay floaty! 🌈✨

πŸ“¦ where this page comes from