aboutsummaryrefslogtreecommitdiff
path: root/src/scalar.c
diff options
context:
space:
mode:
authorCsaba Kertesz <csaba.kertesz@gmail.com>2017-01-15 13:56:31 +0200
committerCsaba Kertesz <csaba.kertesz@gmail.com>2017-01-15 13:56:31 +0200
commit4da3ee149a945cb587deecf262d00bc5ff0f7289 (patch)
tree54f05f9a2ebe24009a2a7c213e59f8ef7ce1ad8d /src/scalar.c
parent287b66756afd9fa44e3605b8eca650852b315003 (diff)
downloadLibXtract-4da3ee149a945cb587deecf262d00bc5ff0f7289.tar.gz
LibXtract-4da3ee149a945cb587deecf262d00bc5ff0f7289.tar.bz2
LibXtract-4da3ee149a945cb587deecf262d00bc5ff0f7289.zip
Don't store the floor() result in integer because it can be out-of-range
Diffstat (limited to 'src/scalar.c')
-rw-r--r--src/scalar.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/src/scalar.c b/src/scalar.c
index 95b296b..065566e 100644
--- a/src/scalar.c
+++ b/src/scalar.c
@@ -301,8 +301,8 @@ int xtract_irregularity_j(const double *data, const int N, const void *argv, dou
int xtract_tristimulus_1(const double *data, const int N, const void *argv, double *result)
{
- int n = N >> 1, h = 0, i;
- double den = 0.0, p1 = 0.0, fund = 0.0, temp = 0.0;
+ int n = N >> 1, i;
+ double den = 0.0, p1 = 0.0, fund = 0.0, temp = 0.0, h = 0.0;
const double *freqs;
fund = *(double *)argv;
@@ -314,7 +314,7 @@ int xtract_tristimulus_1(const double *data, const int N, const void *argv, doub
{
den += temp;
h = floor(freqs[i] / fund + 0.5);
- if(h == 1)
+ if(h > 0 && h < 2 && (int)h == 1)
p1 += temp;
}
}
@@ -333,10 +333,9 @@ int xtract_tristimulus_1(const double *data, const int N, const void *argv, doub
int xtract_tristimulus_2(const double *data, const int N, const void *argv, double *result)
{
-
- int n = N >> 1, h = 0, i;
- double den, p2, p3, p4, ps, fund, temp;
- den = p2 = p3 = p4 = ps = fund = temp = 0.0;
+ int n = N >> 1, i;
+ double den, p2, p3, p4, ps, fund, temp, h;
+ den = p2 = p3 = p4 = ps = fund = temp = h = 0.0;
const double *freqs;
fund = *(double *)argv;
@@ -348,21 +347,24 @@ int xtract_tristimulus_2(const double *data, const int N, const void *argv, doub
{
den += temp;
h = floor(freqs[i] / fund + 0.5);
- switch (h)
+ if (h > 1 && h < 5)
{
- case 2:
- p2 += temp;
+ switch ((int)h)
+ {
+ case 2:
+ p2 += temp;
break;
- case 3:
- p3 += temp;
+ case 3:
+ p3 += temp;
break;
- case 4:
- p4 += temp;
+ case 4:
+ p4 += temp;
- default:
- break;
+ default:
+ break;
+ }
}
}
}
@@ -384,8 +386,8 @@ int xtract_tristimulus_2(const double *data, const int N, const void *argv, doub
int xtract_tristimulus_3(const double *data, const int N, const void *argv, double *result)
{
- int n = N >> 1, h = 0, i;
- double den = 0.0, num = 0.0, fund = 0.0, temp = 0.0;
+ int n = N >> 1, i;
+ double den = 0.0, num = 0.0, fund = 0.0, temp = 0.0, h = 0.0;
const double *freqs;
fund = *(double *)argv;