generalizedHarmonic
Computes the generalized harmonic number H(n, s) = Σ_{i=1}^{n} 1/i^s.
Uses Neumaier compensated summation (inline, no array allocation) for numerical accuracy. The ordinary harmonic number is the special case s = 1. When s = 0, the result equals n.
Example:
generalizedHarmonic(10, 1.0) // 2.92896... (10th harmonic number)
generalizedHarmonic(5, 0.0) // 5.0
generalizedHarmonic(0, 2.0) // 0.0 (empty sum)Content copied to clipboard
Return
Parameters
n
the upper summation limit. Must be non-negative.
s
the exponent applied to each term.