Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/numeric/special functions/riemann zeta"

From cppreference.com
m (Text replace - "special_math" to "special_functions")
m (dcl header)
Line 2: Line 2:
 
{{cpp/numeric/special_functions/navbar}}
 
{{cpp/numeric/special_functions/navbar}}
 
{{dcl begin}}
 
{{dcl begin}}
 +
{{dcl header | cmath}}
 
{{dcl |num=1|since=c++17|
 
{{dcl |num=1|since=c++17|
 
double      riemann_zeta( double arg );
 
double      riemann_zeta( double arg );
Line 63: Line 64:
 
[http://mathworld.wolfram.com/RiemannZetaFunction.html Weisstein, Eric W. "Riemann Zeta Function."] From MathWorld--A Wolfram Web Resource.
 
[http://mathworld.wolfram.com/RiemannZetaFunction.html Weisstein, Eric W. "Riemann Zeta Function."] From MathWorld--A Wolfram Web Resource.
  
[[de:cpp/numeric/special_functions/riemann_zeta]]
+
{{langlinks|de|es|fr|it|ja|pt|ru|zh}}
[[es:cpp/numeric/special_functions/riemann_zeta]]
+
[[fr:cpp/numeric/special_functions/riemann_zeta]]
+
[[it:cpp/numeric/special_functions/riemann_zeta]]
+
[[ja:cpp/numeric/special_functions/riemann_zeta]]
+
[[pt:cpp/numeric/special_functions/riemann_zeta]]
+
[[ru:cpp/numeric/special_functions/riemann_zeta]]
+
[[zh:cpp/numeric/special_functions/riemann_zeta]]
+

Revision as of 07:22, 29 November 2019

 
 
 
 
Defined in header <cmath>
double      riemann_zeta( double arg );

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

long double riemann_zetal( long double arg );
(1) (since C++17)
double      riemann_zeta( IntegralType arg );
(2) (since C++17)
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.

Contents

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 0≤arg≤1,
    1
    1-21-arg
    Σ∞n=1(-1)n-1n-arg
  • For arg<0, 2argπarg-1sin(
    πarg
    2
    )Γ(1−arg)ζ(1−arg)

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.