LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
fj_harmonic.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2012-2026, QORE Lab, Imperial College London
3
* All rights reserved.
4
*/
5
#ifndef LINE_API_FJ_HARMONIC_H
6
#define LINE_API_FJ_HARMONIC_H
7
8
/**
9
* @file
10
* @ingroup api_fj
11
* Harmonic number H_K = sum_{k=1..K} 1/k.
12
*
13
* Templated port of matlab/src/api/fj/fj_harmonic.m, cross-checked against
14
* jar/src/main/java/jline/api/fj/FJ_harmonic.java (identical).
15
*
16
* H_K is the expected maximum of K i.i.d. unit-rate exponentials and so is the
17
* single most reused quantity in the fork-join family. It is a sum of unit
18
* fractions, hence exactly representable in the field: the exact instantiation
19
* returns the true rational H_K, which the double one does not (the summation
20
* loses the low bits from about K = 10 onwards and the alternating sums in
21
* fj_respt_vm and fj_xmax_erlang amplify that loss).
22
*/
23
24
#include "
line/api/fj/fj_types.h
"
25
#include "
line/num/number.h
"
26
27
namespace
line
{
28
namespace
fj
{
29
30
/**
31
* @brief Harmonic number H_K = sum_{k=1..K} 1/k.
32
*
33
* @param K number of parallel branches, K >= 1
34
* @return H_K = 1 + 1/2 + ... + 1/K
35
*/
36
template
<
class
T>
37
T
fj_harmonic
(
unsigned
K) {
38
detail::require_positive_K(K,
"fj_harmonic"
);
39
T H =
num_traits<T>::from_int
(0);
40
for
(
unsigned
k = 1; k <= K; ++k) H += num_traits<T>::from_int(1) /
num_traits<T>::from_int
(
static_cast<
long
>
(k));
41
return
H;
42
}
43
44
}
// namespace fj
45
}
// namespace line
46
47
#endif
// LINE_API_FJ_HARMONIC_H
fj_types.h
Shared return types and arithmetic helpers for the templated fork-join port.
line::fj
Definition
fj_amva.h:34
line::fj::fj_harmonic
T fj_harmonic(unsigned K)
Harmonic number H_K = sum_{k=1..K} 1/k.
Definition
fj_harmonic.h:37
line
Definition
aoi_dist2ph.h:52
number.h
Number-type abstraction for the templated API port.
line::num_traits
Definition
number.h:111
include
line
api
fj
fj_harmonic.h
Generated by
1.18.0