std::rieman...iemann_zetal(3)

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

NAME πŸ’–

std::riemann_zeta, std::riemann_zetaf, std::riemann_zetal β€” like, the Riemann zeta function but make it C++ Standard Library, bestie ✨ (manual page, section 3, no cap).


Synopsis ✨

Okay so here's the whole squad of signatures, exactly as written, slay:

          double      riemann_zeta( double arg );

          double      riemann_zeta( float arg );
          double      riemann_zeta( long double arg );  (1)
          float       riemann_zetaf( float arg );

          long double riemann_zetal( long double arg );
          double      riemann_zeta( IntegralType arg ); (2)
  1. Computes the Riemann zeta function of arg.
  2. A set of overloads or a function template accepting an argument of any integral type. Equivalent to (1) after casting the argument to double.

As all special functions, riemann_zeta is only guaranteed to be available in <cmath> if __STDCPP_MATH_SPEC_FUNCS__ is defined by the implementation to a value at least 201003L and if the user defines __STDCPP_WANT_MATH_SPEC_FUNCS__ before including any standard library headers. Like, read that twice, it's giving prerequisites πŸ’….


Parameters πŸŽ€

  • arg β€” value of a floating-point or integral type. That's the vibe check input, bestie.

Return value πŸ¦‹

If no errors occur, you get the value of the Riemann zeta function of arg, ΞΆ(arg), defined for the entire real axis. Here's the formula lore, copied exactly because math is iconic and we do not paraphrase:

  • For arg > 1,
Σ∞
n=1n-arg
.
  • For 0 ≀ arg ≀ 1,
1
1 - 21-arg

Σ∞
n=1(-1)n-1
n-arg
.
  • For arg < 0,
2arg
Ο€arg-1
sin(

Ο€arg
2

)Ξ“(1 βˆ’ arg)ΞΆ(1 βˆ’ arg).

No cap, that's the whole definition across the real axis 🌈.


Error handling 🌸

Errors may be reported as specified in math_errhandling. Periodt.

  • If the argument is NaN, NaN is returned and domain error is not reported. So like, NaN in, NaN out, no drama πŸ’€.

Notes πŸ’…

Implementations that do not support TR 29124 but support TR 19768, provide this function in the header tr1/cmath and namespace std::tr1. Nostalgic much?

An implementation of this function is also available in boost.math. So if you're boost-pilled, you already know, iykyk 🧚.


Example 🫢

(works as shown with gcc 6.0) β€” literally noted, so don't come for me if your compiler is being quirky.

// Run this code

#define __STDCPP_WANT_MATH_SPEC_FUNCS__ 1
#include <cmath>
#include <iostream>

int main()
{
    // spot checks for well-known values
    std::cout << "ΞΆ(-1) = " << std::riemann_zeta(-1) << '\n'
              << "ΞΆ(0) = " << std::riemann_zeta(0) << '\n'
              << "ΞΆ(1) = " << std::riemann_zeta(1) << '\n'
              << "ΞΆ(0.5) = " << std::riemann_zeta(0.5) << '\n'
              << "ΞΆ(2) = " << std::riemann_zeta(2) << ' '
              << "(π²/6 = " << std::pow(std::acos(-1), 2) / 6 << ")\n";
}

Output 😭

ΞΆ(-1) = -0.0833333
ΞΆ(0) = -0.5
ΞΆ(1) = inf
ΞΆ(0.5) = -1.46035
ΞΆ(2) = 1.64493 (π²/6 = 1.64493)

The way ΞΆ(1) = inf just shows up like that? Main character energy fr fr πŸ”₯.


Weisstein, Eric W. "Riemann Zeta Function." From MathWorld--A Wolfram Web Resource.


Okay bestie, that's the whole page πŸ«ΆπŸ’–βœ¨ Source/version and date, in cute sign-off form: this iconic little manual came from http://cppreference.com, dated 2024.06.10, and its page tag is std::rieman...iemann_zetal(3). Slay πŸŒΈπŸ‘‘.

πŸ“¦ where this page comes from