Click here to Skip to main content
15,895,799 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionGet CPU Usage of each CPU for a process running on multi CPUs system Pin
lvantin9-Feb-06 20:50
lvantin9-Feb-06 20:50 
QuestionListBox Pin
NoxMan9-Feb-06 20:36
NoxMan9-Feb-06 20:36 
AnswerRe: ListBox Pin
Owner drawn9-Feb-06 21:19
Owner drawn9-Feb-06 21:19 
GeneralRe: ListBox Pin
NoxMan9-Feb-06 22:39
NoxMan9-Feb-06 22:39 
QuestionSummation of Floating-point values. Best accuracy. Pin
dmivlad9-Feb-06 20:22
dmivlad9-Feb-06 20:22 
AnswerRe: Summation of Floating-point values. Best accuracy. Pin
Ryan Binns9-Feb-06 21:46
Ryan Binns9-Feb-06 21:46 
GeneralRe: Summation of Floating-point values. Best accuracy. Pin
dmivlad9-Feb-06 23:35
dmivlad9-Feb-06 23:35 
GeneralRe: Summation of Floating-point values. Best accuracy. Pin
Ryan Binns10-Feb-06 12:21
Ryan Binns10-Feb-06 12:21 
Floating point variables only have a limited amount of precision. They can represent very large and very small numbers, but if they represent a very large number, they can't keep track of all the decimal places. A double has about 15 digits of precision, but can represent numbers up to about 10308.

Say you're adding two numbers, 100000000000000.0 and 0.000001. The answer is obviously 100000000000000.000001. However, a double type only has 15 digits of precision, so it rounds this to 100000000000000. Even if you add 0.000001 to this number a billion times, you'll still get the same result - the intermediate results are rounded down because the double type can't support enough digits of precision.

The solution is to add the numbers from smallest to largest - so that you're always adding together numbers that have similar numbers of digits. This way the double type is not required to have large numbers of digits of precision. Therefore, your results do not lose as much precision, and the result is more accurate.

Technically, you can go even better than summing smallest to largest. The most accurate solution is actually to sum the results in a sort of tree structure, where you sum each pair of adjacent values and store the intermediate results, then go back and sum the adjacent pairs of intermediate results, until you get to a single result at the end:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
 3   7   11  15  19    23    27    31 
   10      26       42          58
       36                100
               136
This will give you the absolute greatest accuracy possible, but the effort is not worth the complexity in the calculation unless you absolutely need the accuracy. Summing smallest to largest is usually the best solution.

Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

GeneralRe: Summation of Floating-point values. Best accuracy. Pin
dmivlad12-Feb-06 19:00
dmivlad12-Feb-06 19:00 
QuestionRead Data from file to CString Pin
anilksingh9-Feb-06 19:58
anilksingh9-Feb-06 19:58 
AnswerRe: Read Data from file to CString Pin
ThatsAlok10-Feb-06 0:02
ThatsAlok10-Feb-06 0:02 
QuestionMac Os Installation Problem Pin
Girish6019-Feb-06 19:39
Girish6019-Feb-06 19:39 
AnswerRe: Mac Os Installation Problem Pin
ThatsAlok10-Feb-06 0:41
ThatsAlok10-Feb-06 0:41 
QuestionOpening other application from our own application Pin
Katamneni9-Feb-06 18:42
Katamneni9-Feb-06 18:42 
AnswerRe: Opening other application from our own application Pin
Cool Ju9-Feb-06 19:30
Cool Ju9-Feb-06 19:30 
AnswerRe: Opening other application from our own application Pin
csc9-Feb-06 20:38
csc9-Feb-06 20:38 
QuestionDifference between Typedef and #define? Pin
Link26009-Feb-06 18:23
Link26009-Feb-06 18:23 
AnswerRe: Difference between Typedef and #define? Pin
QuickDeveloper9-Feb-06 18:51
QuickDeveloper9-Feb-06 18:51 
AnswerRe: Difference between Typedef and #define? Pin
Rage9-Feb-06 21:20
professionalRage9-Feb-06 21:20 
GeneralRe: Difference between Typedef and #define? Pin
BadKarma9-Feb-06 22:07
BadKarma9-Feb-06 22:07 
GeneralRe: Difference between Typedef and #define? Pin
Rage10-Feb-06 1:25
professionalRage10-Feb-06 1:25 
GeneralRe: Difference between Typedef and #define? Pin
BadKarma10-Feb-06 2:15
BadKarma10-Feb-06 2:15 
GeneralRe: Difference between Typedef and #define? Pin
Rage10-Feb-06 2:55
professionalRage10-Feb-06 2:55 
GeneralRe: Difference between Typedef and #define? Pin
Ryan Binns10-Feb-06 11:58
Ryan Binns10-Feb-06 11:58 
GeneralRe: Difference between Typedef and #define? Pin
normanS12-Feb-06 20:14
normanS12-Feb-06 20:14 

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.