Common mathematical functions | |||||||||||||||||||||||||||||||
Mathematical special functions(C++17) | |||||||||||||||||||||||||||||||
Mathematical constants(C++20) | |||||||||||||||||||||||||||||||
Basic linear algebra algorithms(C++26) | |||||||||||||||||||||||||||||||
Data-parallel types (SIMD)(C++26) | |||||||||||||||||||||||||||||||
Floating-point environment(C++11) | |||||||||||||||||||||||||||||||
Complex numbers | |||||||||||||||||||||||||||||||
Numeric array (valarray ) | |||||||||||||||||||||||||||||||
Pseudo-random number generation | |||||||||||||||||||||||||||||||
Bit manipulation(C++20) | |||||||||||||||||||||||||||||||
Saturation arithmetic(C++26) | |||||||||||||||||||||||||||||||
Factor operations | |||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||
Interpolations | |||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||
Generic numeric operations | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
C-style checked integer arithmetic | |||||||||||||||||||||||||||||||
|
Defined in header <cmath> | ||
(1) | ||
float riemann_zeta(float num); double riemann_zeta(double num); | (since C++17) (until C++23) | |
/* floating-point-type */ riemann_zeta(/* floating-point-type */ num); | (since C++23) | |
float riemann_zetaf(float num); | (2) | (since C++17) |
longdouble riemann_zetal(longdouble num); | (3) | (since C++17) |
Defined in header <cmath> | ||
template<class Integer> double riemann_zeta( Integer num); | (A) | (since C++17) |
std::riemann_zeta
for all cv-unqualified floating-point types as the type of the parameternum.(since C++23)Contents |
num | - | floating-point or value |
If no errors occur, value of the Riemann zeta function ofnum,ζ(num), defined for the entire real axis:
1 |
21-num -1 |
πnum |
2 |
Errors may be reported as specified inmath_errhandling.
Implementations that do not support C++17, but supportISO 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 headertr1/cmath
and namespacestd::tr1
.
An implementation of this function is alsoavailable in boost.math.
The additional overloads are not required to be provided exactly as(A). They only need to be sufficient to ensure that for their argumentnum of integer type,std::riemann_zeta(num) has the same effect asstd::riemann_zeta(static_cast<double>(num)).
#include <cmath>#include <format>#include <iostream>#include <numbers> int main(){constexprauto π=std::numbers::pi; // spot checks for well-known valuesfor(constdouble x:{-1.0,0.0,1.0,0.5,2.0})std::cout<<std::format("ζ({})\t= {:+.5f}\n", x, std::riemann_zeta(x));std::cout<<std::format("π²/6\t= {:+.5f}\n", π* π/6);}
Output:
ζ(-1) = -0.08333ζ(0) = -0.50000ζ(1) = +infζ(0.5) = -1.46035ζ(2) = +1.64493π²/6 = +1.64493
Weisstein, Eric W. "Riemann Zeta Function." From MathWorld — A Wolfram Web Resource. |