A
Anton Noll
We are using Visual Studio 2003.NET (C++) for the development
of our software in the fields digital signal processing and
numerical acoustics.
One of our programs was working correctly if we are using the
Debug-Version of the program, but it fails (or leads to false
results) if we are using the Release-Version. After a long
debugging session we found out, that our program was working
correctly, but the floating point processing (accuracy) of the
Debug-Version and the Release-Version is different and leads to
different numerical results.
This bug occurs independend of the optimization level which is
used for the Release-Version (even if optimization is disabled).
We have dedected this bug only in the C++ compiler of Visual
Studio 2003.NET. With Visual Studio 6 both versions of our
program are working (with the same results).
I have included a test program in this mail. If the program
below is compiled with Visual Studio 2003.NET the output of
the Debug- and the Release-Version is differnt.
Note: There is also a problem with casting floats to int. This
means, in some cases the result of "(int)x" in the Debug- and
the Release-Vesion is not the same.
I have tried to report this bug/problem to the microsoft company,
but after visiting a lot of web-pages without any chance to send
a note to microsoft i gave up.
Anton Noll
Austrian Academy of Sciences, Acoustics Research Institut
1010 Vienna, Reichsratstrasse 17, Austria
E-Mail: (e-mail address removed)
Test program (a part of a fir filter development algorithm)
----- BEGIN OF NUMTEST.CPP -----
// numtest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
static float _dfunci0(float x)
{
float sa, uh, u=1, s=1;
int i = 1;
while(true)
{
sa = s;
uh = x / 2 / (float)i++;
u = u * uh * uh;
s = s + u;
if(sa == s) return s;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
float delta = (float)1e-6, freq = (float)1;
float fe = (float)0.05, fg = (float)0.1;
int k, n;
float pi, a, df, fs, alpha, wn, hilf;
float *cw, *w,*c;
pi = (float)atan2((float)0,(float)-1);
a = (float)(-20 * log10(delta));
df = (fg-fe) / freq;
fs = (fg+fe) / 2 / freq;
n = int((a - 7.95) / 28.72 / df) + 1;
cw = new float[n+1];
c = new float[n+1];
w = new float[n+1];
if(a > 50)
alpha = (float)(0.1102 * (a-8.7));
else if(a > 21)
alpha = (float)(pow(0.5842*(a-21),0.4) + 0.07886*(a-21));
else
alpha = 0;
c[0] = 2*fs;
for(k = 1;k <= n; k++)
c[k] = sin(2 * pi * k * fs) / (pi * k);
wn = _dfunci0(alpha);
for(k = 0;k <= n; k++)
{
hilf = (float)1 - (float)(k*k) / (float)(n*n);
if(hilf <= 0)
hilf = 0;
else
hilf = alpha * sqrt(hilf);
w[k] = _dfunci0(hilf) / wn;
}
for(k = 0; k <= n; k++)
cw[k] = (float)(c[k] * w[k]);
FILE *test = fopen("numtest.txt","wt");
for(k = 0; k <= n; k++)
fprintf(test,"%g,%g,%g\n", c[k], w[k], cw[k]);
fclose(test);
return 0;
}
----- END OF NUMTEST.CPP -----
of our software in the fields digital signal processing and
numerical acoustics.
One of our programs was working correctly if we are using the
Debug-Version of the program, but it fails (or leads to false
results) if we are using the Release-Version. After a long
debugging session we found out, that our program was working
correctly, but the floating point processing (accuracy) of the
Debug-Version and the Release-Version is different and leads to
different numerical results.
This bug occurs independend of the optimization level which is
used for the Release-Version (even if optimization is disabled).
We have dedected this bug only in the C++ compiler of Visual
Studio 2003.NET. With Visual Studio 6 both versions of our
program are working (with the same results).
I have included a test program in this mail. If the program
below is compiled with Visual Studio 2003.NET the output of
the Debug- and the Release-Version is differnt.
Note: There is also a problem with casting floats to int. This
means, in some cases the result of "(int)x" in the Debug- and
the Release-Vesion is not the same.
I have tried to report this bug/problem to the microsoft company,
but after visiting a lot of web-pages without any chance to send
a note to microsoft i gave up.
Anton Noll
Austrian Academy of Sciences, Acoustics Research Institut
1010 Vienna, Reichsratstrasse 17, Austria
E-Mail: (e-mail address removed)
Test program (a part of a fir filter development algorithm)
----- BEGIN OF NUMTEST.CPP -----
// numtest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
static float _dfunci0(float x)
{
float sa, uh, u=1, s=1;
int i = 1;
while(true)
{
sa = s;
uh = x / 2 / (float)i++;
u = u * uh * uh;
s = s + u;
if(sa == s) return s;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
float delta = (float)1e-6, freq = (float)1;
float fe = (float)0.05, fg = (float)0.1;
int k, n;
float pi, a, df, fs, alpha, wn, hilf;
float *cw, *w,*c;
pi = (float)atan2((float)0,(float)-1);
a = (float)(-20 * log10(delta));
df = (fg-fe) / freq;
fs = (fg+fe) / 2 / freq;
n = int((a - 7.95) / 28.72 / df) + 1;
cw = new float[n+1];
c = new float[n+1];
w = new float[n+1];
if(a > 50)
alpha = (float)(0.1102 * (a-8.7));
else if(a > 21)
alpha = (float)(pow(0.5842*(a-21),0.4) + 0.07886*(a-21));
else
alpha = 0;
c[0] = 2*fs;
for(k = 1;k <= n; k++)
c[k] = sin(2 * pi * k * fs) / (pi * k);
wn = _dfunci0(alpha);
for(k = 0;k <= n; k++)
{
hilf = (float)1 - (float)(k*k) / (float)(n*n);
if(hilf <= 0)
hilf = 0;
else
hilf = alpha * sqrt(hilf);
w[k] = _dfunci0(hilf) / wn;
}
for(k = 0; k <= n; k++)
cw[k] = (float)(c[k] * w[k]);
FILE *test = fopen("numtest.txt","wt");
for(k = 0; k <= n; k++)
fprintf(test,"%g,%g,%g\n", c[k], w[k], cw[k]);
fclose(test);
return 0;
}
----- END OF NUMTEST.CPP -----