Click here to Skip to main content
16,004,686 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generalhyperterminal Pin
Sunnygirl13-Feb-03 5:50
Sunnygirl13-Feb-03 5:50 
GeneralRe: hyperterminal Pin
Artem Moroz13-Feb-03 8:48
Artem Moroz13-Feb-03 8:48 
General#error WINDOWS.H already included Pin
Larsson13-Feb-03 5:42
Larsson13-Feb-03 5:42 
GeneralRe: #error WINDOWS.H already included Pin
Joseph Dempsey13-Feb-03 5:52
Joseph Dempsey13-Feb-03 5:52 
GeneralRe: #error WINDOWS.H already included Pin
Larsson13-Feb-03 5:58
Larsson13-Feb-03 5:58 
GeneralRe: #error WINDOWS.H already included Pin
Joseph Dempsey13-Feb-03 8:31
Joseph Dempsey13-Feb-03 8:31 
GeneralRe: #error WINDOWS.H already included Pin
Anonymous13-Feb-03 17:01
Anonymous13-Feb-03 17:01 
GeneralRound-off errors Pin
Anton A. Loukine13-Feb-03 5:15
Anton A. Loukine13-Feb-03 5:15 
Hi:

I am not able to explain this behaviour:

1. The following code produces 0.013721122105938371, which is correct:

printf("\n\n%4.25Lf\n\n", + mBase[3][3] * exp( -4.0 * fAlpha * fPeriod )
+ mBase[3][2] * exp( -3.0 * fAlpha * fPeriod )
+ mBase[3][1] * exp( -2.0 * fAlpha * fPeriod )
+ mBase[3][0] * exp( -1.0 * fAlpha * fPeriod ));

2. The following code also produces the same number:

double a,b,c,d;

a = mBase[3][3] * exp( -4.0 * fAlpha * fPeriod );
b = mBase[3][2] * exp( -3.0 * fAlpha * fPeriod );
c = mBase[3][1] * exp( -2.0 * fAlpha * fPeriod );
d = mBase[3][0] * exp( -1.0 * fAlpha * fPeriod );

printf("\n\n%4.25Lf\n\n", a+b+c+d);

3. But this code produces a slightly different number 0.013721122105938344 (error in the last 2 digits for a relatively small loop! for larger loops it only gets worse!):

int n;
double fOrthonormal = 0.0;
for (n = 0; n <= 3; n++) {
fOrthonormal += mBase[3][n] * exp( -( double )(n + 1) * fAlpha * fPeriod);
}


4. MOreover this code, surprisingly also produces a different number!

int n;
double fOrthonormal = 0.0;
for (n = 3; n >= 0; n--) {
fOrthonormal += mBase[3][n] * exp( -( double )(n + 1) * fAlpha * fPeriod);
}

Precision in my case is important. It looks like it's really sensitive to the order in which numbers are added. But when I would intuitively expect an error in the last digit only (for a 4 item loop), it produces an error in the last 2 or 3! Any ideas why this happens?

IS THERE A BETTER NUMBER CLASS TO USE WHEN PRECISION MATTERS?

Thanks
GeneralRe: Round-off errors Pin
Chris Losinger13-Feb-03 5:26
professionalChris Losinger13-Feb-03 5:26 
GeneralRe: Round-off errors Pin
Tim Smith13-Feb-03 5:36
Tim Smith13-Feb-03 5:36 
GeneralRe: Round-off errors Pin
Roger Allen13-Feb-03 5:59
Roger Allen13-Feb-03 5:59 
GeneralRe: Round-off errors Pin
Scorp1us13-Feb-03 7:46
Scorp1us13-Feb-03 7:46 
GeneralRe: Round-off errors Pin
Tim Smith13-Feb-03 11:35
Tim Smith13-Feb-03 11:35 
GeneralRe: Round-off errors Pin
Anonymous13-Feb-03 17:04
Anonymous13-Feb-03 17:04 
GeneralRe: Round-off errors Pin
Mike Nordell13-Feb-03 13:26
Mike Nordell13-Feb-03 13:26 
GeneralCTabCtrl and getting mouse events Pin
Jim Crafton13-Feb-03 4:59
Jim Crafton13-Feb-03 4:59 
GeneralError I don't get it please help me.... Pin
Larsson13-Feb-03 4:23
Larsson13-Feb-03 4:23 
GeneralRe: Error I don't get it please help me.... Pin
Andreas Saurwein13-Feb-03 4:26
Andreas Saurwein13-Feb-03 4:26 
GeneralRe: Error I don't get it please help me.... Pin
Larsson13-Feb-03 4:28
Larsson13-Feb-03 4:28 
GeneralRe: Error I don't get it please help me.... Pin
Andreas Saurwein13-Feb-03 4:34
Andreas Saurwein13-Feb-03 4:34 
GeneralRe: Error I don't get it please help me.... Pin
Larsson13-Feb-03 5:14
Larsson13-Feb-03 5:14 
GeneralRe: Error I don't get it please help me.... Pin
Andreas Saurwein13-Feb-03 5:53
Andreas Saurwein13-Feb-03 5:53 
GeneralRe: Error I don't get it please help me.... Pin
Larsson13-Feb-03 6:11
Larsson13-Feb-03 6:11 
GeneralProblems Using HWND_BROADCAST Pin
#realJSOP13-Feb-03 3:40
professional#realJSOP13-Feb-03 3:40 
GeneralRe: Problems Using HWND_BROADCAST Pin
Jörgen Sigvardsson13-Feb-03 4:08
Jörgen Sigvardsson13-Feb-03 4:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.