std::riemann_zeta, std::riemann_zetaf, std::riemann_zetal
double riemann_zeta( double arg ); double riemann_zeta( float arg ); |
(1) | (since C++17) |
double riemann_zeta( IntegralType arg ); |
(2) | (since C++17) |
Parameters
arg | - | value of a floating-point or integral type |
Return value
If no errors occur, value of the Riemann zeta function of arg
, (arg), defined for the entire real axis:
- For arg>1,
n=1n-arg
- For 0arg1,
1 1-21-arg
n=1(-1)n-1
n-arg
- For arg<0, 2arg
arg-1
sin(
)(1arg)(1arg)arg 2
Error handling
Errors may be reported as specified in math_errhandling
- If the argument is NaN, NaN is returned and domain error is not reported
Notes
Implementations that do not support C++17, but support ISO 29124:2010, provide this function 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.
Implementations that do not support ISO 29124:2010 but support TR 19768:2007 (TR1), provide this function in the header tr1/cmath
and namespace std::tr1
An implementation of this function is also available in boost.math
Example
#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)
External links
Weisstein, Eric W. "Riemann Zeta Function." From MathWorld--A Wolfram Web Resource.