Mercurial > hg > x
comparison procedures.cpp @ 3:42c078b19e9a
* Replace null-pointer hack with use of standard macro offsetof(struct,member)
author | Chris Cannam |
---|---|
date | Tue, 05 Oct 2010 16:18:52 +0100 |
parents | fc19d45615d1 |
children | 5f3c32dc6e17 |
comparison
equal
deleted
inserted
replaced
2:fc19d45615d1 | 3:42c078b19e9a |
---|---|
1 //--------------------------------------------------------------------------- | 1 //--------------------------------------------------------------------------- |
2 | 2 |
3 #include <math.h> | 3 #include <math.h> |
4 #include <string.h> | 4 #include <string.h> |
5 #include <stddef.h> | |
5 #include "procedures.h" | 6 #include "procedures.h" |
6 #include "matrix.h" | 7 #include "matrix.h" |
7 #include "opt.h" | 8 #include "opt.h" |
8 #include "sinest.h" | 9 #include "sinest.h" |
9 | 10 |
1422 Returns the number of peaks detected. | 1423 Returns the number of peaks detected. |
1423 */ | 1424 */ |
1424 int HxPeak2(double*& hps, double*& vhps, double (*F)(double, void*), double (*dF)(double, void*), double(*ddF)(double, void*), void* params, double st, double en, double epf) | 1425 int HxPeak2(double*& hps, double*& vhps, double (*F)(double, void*), double (*dF)(double, void*), double(*ddF)(double, void*), void* params, double st, double en, double epf) |
1425 { | 1426 { |
1426 struct l_hx {int N; union {double B; struct {int k1; int k2;};}; cdouble* x; double dhxpeak; double hxpeak;} *p=(l_hx *)params; | 1427 struct l_hx {int N; union {double B; struct {int k1; int k2;};}; cdouble* x; double dhxpeak; double hxpeak;} *p=(l_hx *)params; |
1427 int dfshift=int(&((l_hx*)0)->dhxpeak); | 1428 int dfshift=offsetof(l_hx, dhxpeak); |
1428 int fshift=int(&((l_hx*)0)->hxpeak); | 1429 int fshift=offsetof(l_hx, hxpeak); |
1429 double B=p->B; | 1430 double B=p->B; |
1430 int count=0; | 1431 int count=0; |
1431 | 1432 |
1432 int den=ceil(en), dst=floor(st); | 1433 int den=ceil(en), dst=floor(st); |
1433 if (den-dst<3) den++, dst--; | 1434 if (den-dst<3) den++, dst--; |
2409 Returns the integral of f(*, params) over [a, b]. | 2410 Returns the integral of f(*, params) over [a, b]. |
2410 */ | 2411 */ |
2411 double Romberg(int n, double(*f)(double, void*), double a, double b, void* params) | 2412 double Romberg(int n, double(*f)(double, void*), double a, double b, void* params) |
2412 { | 2413 { |
2413 int np=1; | 2414 int np=1; |
2414 double* r1=new double[n+1];. | 2415 double* r1=new double[n+1]; |
2415 double* r2=new double[n+1]; | 2416 double* r2=new double[n+1]; |
2416 double h=b-a, *swp; | 2417 double h=b-a, *swp; |
2417 r1[1]=h*(f(a, params)+f(b, params))/2; | 2418 r1[1]=h*(f(a, params)+f(b, params))/2; |
2418 for (int i=2; i<=n; i++) | 2419 for (int i=2; i<=n; i++) |
2419 { | 2420 { |