-
Notifications
You must be signed in to change notification settings - Fork 0
/
plouffe.C
93 lines (75 loc) · 1.67 KB
/
plouffe.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* plouffe.C
*
* FUNCTION:
* display plouffe-type q-series
*
* HISTORY:
* quick hack -- Linas Vepstas October 1989
* modernize -- Linas Vepstas March 1996
* more stuff -- January 2000
* more stuff -- October 2004
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "brat.h"
static double ess;
static int max_terms;
static void plouffe_series_c (double re_q, double im_q, double *prep, double *pimp)
{
double tmp;
int n;
*prep = 0.0;
*pimp = 0.0;
double rep = 0.0;
double imp = 0.0;
double qpr = re_q;
double qpi = im_q;
double qpmod = re_q*re_q+im_q*im_q;
if (1.0 <= qpmod) return;
for (n=1; n<max_terms; n++)
{
/* compute n^(-s) */
double term = pow (n, -ess);
/* compute 1/(q^n-1) */
double qmr = qpr-1.0;
double qmi = qpi;
double qm = qmr*qmr + qmi*qmi;
double qvr = qmr/qm;
double qvi = -qmi/qm;
rep += qvr *term;
imp += qvi *term;
/* compute q^n */
tmp = qpr*re_q - qpi * im_q;
qpi = qpr*im_q + qpi * re_q;
qpr = tmp;
qpmod = qpr*qpr + qpi*qpi;
if (qpmod < 1.0e-30) break;
}
if (max_terms-1 < n)
{
// printf ("not converged re=%g im=%g modulus=%g\n", re_q, im_q, qpmod);
}
*prep = rep;
*pimp = imp;
}
static double plouffe_series (double re_q, double im_q, int itermax, double param)
{
max_terms = itermax;
ess = param;
double rep, imp;
plouffe_series_c (re_q, im_q, &rep, &imp);
// return sqrt (rep*rep+imp*imp);
// return (atan2 (imp, rep)+M_PI) / (2.0*M_PI);
double ph = (atan2 (imp, rep)+M_PI) / (2.0*M_PI);
/*
ph += 0.5;
if (1.0<ph) ph -= 1.0;
ph -= 0.5;
*/
return ph;
// return -rep;
}
DECL_MAKE_HEIGHT(plouffe_series);
/* --------------------------- END OF LIFE ------------------------- */