Monday, April 13, 2009

In the pipe five by five

- One by one,
- Two by two,
- Five by five.

The famous saying is

1. "In the pipe five by five." you can hear this word in the game "Starcraft". but the original word in the movie "Aliens". "We're in the pipe, five by five."

2. In the bible, we can find "Noah brought all animals into the ark two by two"

Anything else?

Sunday, April 12, 2009

Code Complete 1, in the floating point

Thin book is a great, wonderful, and fantastic.
How can he write this book, is he a genious?

In the floating point operation,

double dwNormal = 1.0;
double dwSum = 0;

int i = 0;
for (i=0; i<10; i++)
{
dwSum += 0.1;
TRACE("dwSum: %1.20f\n", dwSum);
}

if (dwSum == dwNormal)
{
TRACE("Numbers are the Same.");
}
else
{
TRACE("Numbers are Differnet.");
}

Can you guess the result?
dwSum == dwNormal is True or False?
In normal case, the result is False.
dwSum = 0.99999999999999989
In normal case, floating point precision, usually be represented to only 7 ot 15 digits of accuracy.

dwSum: 0.10000000000000001000
dwSum: 0.20000000000000001000
dwSum: 0.30000000000000004000
dwSum: 0.40000000000000002000
dwSum: 0.50000000000000000000
dwSum: 0.59999999999999998000
dwSum: 0.69999999999999996000
dwSum: 0.79999999999999993000
dwSum: 0.89999999999999991000
dwSum: 0.99999999999999989000

C code refactoring

refactoring & restructuring

refactoring is same input and output of function arguments
just change into the function's code

restructuring is same input and output of function argument or NOT.
In the project middle term, refactoring and/or restructuring
End of project, restructuring is NOT recommended, restructuring is recommended.