Sunday, February 22, 2009

display calculation result, long expression

In the C code, if the input value is very large and include fraction expression,
for example 3.141592 or 6350.29318. And want to display those values exactly.
How can you deal those values?

Now, I'm thinking, I use value shift and divide integer part and decimal part.
 3.141592 = 3 + 0.141592
 6350.29318 = 6350 + 0.29318

In the C language
 First, multiply big or large number
 6350.29318 * E14 = 635029318000000000
 and divide that value 6350 & 29318
 and check the decimal point, i.e., 5
 Second, use the sprintf(...) function
  such as "sprintf(SzTestResult, "%d.%0*d", lInteger, nDecimalPoint, lDecimal);"

And my question is, if there is or are  the C language exporter(s), how he or they deal(s) this issue?


#include
#define SHIFT_SIZE_MAX (14)
#define NUMBER_SHIFT(X) ((X)*pow(10, (SHIFT_SIZE_MAX)))

// ------------------------------------------------------------------------------
// NumberFraction
// Input
//  dInputNumber: Real Number, ABC.DEF
//  *plNaturalNumber: Value of Natural Numner, ABC
//  *plDecimalNumber: Value of Decimal Number, DEF
//  *pnDecimalPoint: Value of Decimal Point, 3
// Return
//  Success: 0
//  Fail: NOT 0
// ------------------------------------------------------------------------------
int NumberFraction(
double dInputNumber, 
unsigned long *plNaturalNumber,
unsigned long *plDecimalNumber,
int *pnDecimalPoint)
{
int nReturnType = 0;

// Input Value
//double dInputNumber = 6350.29318;

// Return Value 
unsigned long lNaturalNumber = 0;
unsigned long lDecimalNumber = 0;
double dDecimalNumberT = 0;
//int nDecimalPoint = 0;

double dShiftedValue = dInputNumber * pow(10, SHIFT_SIZE_MAX);

//  Count Deciaml Number
int nCount = 0;
int nDecimalNumber = 0;
double dInputValue = dShiftedValue;

// Check Input Value
if (plNaturalNumber == NULL)
{
return nReturnType = 2;
}

if (plNaturalNumber == NULL)
{
return nReturnType = 3;
}

if (pnDecimalPoint == NULL)
{
return nReturnType = 4;
}

for(nCount=0; nCount
{
double dVal = 0;
double dFraction = 0;

dInputValue = dInputValue / 10.;

dFraction = modf(dInputValue, &dVal);
if (dFraction == 0.0)
{
continue;
}
else
{
break;
}
}
nDecimalNumber = SHIFT_SIZE_MAX - nCount;

lNaturalNumber = (unsigned long)(dShiftedValue / pow(10, SHIFT_SIZE_MAX));
dDecimalNumberT = dShiftedValue  - (lNaturalNumber * pow(10, SHIFT_SIZE_MAX));
lDecimalNumber = (unsigned long)(dDecimalNumberT / pow(10, nCount));

// Set Return Value
*plNaturalNumber = lNaturalNumber;
*plDecimalNumber = lDecimalNumber;
*pnDecimalPoint = nDecimalNumber;

return nReturnType;
}

// ------------------------------------------------------------------------------
// NumberFraction2String
// Input
//  dInputNumber: Real Number, ABC.DEF
//  pOutputString: "ABC.DEF"
//  nOutputStringSize: SHOULD 32 bytes or more
// Return
//  Success: 0
//  Fail: NOT 0
// ------------------------------------------------------------------------------
int NumberFraction2String(
double dInputNumber, 
char* pOutputString, 
int nOutputStringSize)
{
int nReturnType = 0;

char SzTestResult[32] = {0x00, }; 
char SzZeroString[16] = {0x00, };
char SzDecimalNumber[16] = {0x00, };
int nMaxZeroNumber = 0;

int i = 0;

unsigned long lInteger = 0;
unsigned long lDecimal = 0;
int nDecimalPoint = 0;

// Check Input Value
if (pOutputString == NULL)
{
nReturnType = 2;
}

// memset
memset(pOutputString, 0x00, nOutputStringSize*sizeof(char));

// Convert: InputNumber Fraction, NatualNumber + DecimalNumber
nReturnType = NumberFraction(dInputNumber, &lInteger, &lDecimal, &nDecimalPoint);
if (nReturnType == 0)
{
int nStringSize = 0;

#if 0 // OLD Method
sprintf(SzDecimalNumber, "%d", lDecimal);
nMaxZeroNumber = nDecimalPoint - strlen(SzDecimalNumber);
for (i=0; i
{
SzZeroString[i] = '0';
}
sprintf(SzTestResult, "%d.%s%d", lInteger, SzZeroString, lDecimal);
#else // NEW Method
sprintf(SzTestResult, "%d.%0*d", lInteger, nDecimalPoint, lDecimal);
#endif //
nStringSize = strlen(SzTestResult);

if (nOutputStringSize+1 >= nStringSize)
{
memcpy(pOutputString, SzTestResult, nStringSize*sizeof(char));
}
}
else
{
// error
nReturnType = nReturnType + 10;
}

return nReturnType;
}

// Test Code
//double dTest = 3280.8399;
//double dTest = 0.0000000009842;
double dTest = 1.01660469088;
char SzOutputBuffer[32] = {0x00, };
int nOutputBufferSize = 32;
NumberFraction2String(dTest, SzOutputBuffer, nOutputBufferSize);


Friday, February 20, 2009

::ShellExecute

Previous time, I used "WinExec(...)" function to execute windows application.
But other persion use the other windows API to execute windows application instead of "WinExec(...)". That function name is "ShellExecute(...)".

If you want to open web site (www.google.com) with internet explorer, you can write code as followed
 ::ShellExecute(
     NULL, 
     L"open", 
     L"http://www.google.com", 
     L"", 
     NULL, 
     SW_SHOWNORMAL);
But if you want open NEW web site in the NEW internet explorer, you can write code as followed
 ::ShellExecute(
     NULL, 
     L"open", 
     L"iexplore.exe", 
     L"http://www.apple.com", 
     NULL, 
     SW_SHOWNORMAL); 


How to build UNICODE in the Visual C++ 6.0

In the Visual C++ 6.0, if you want to compile UNICODE code,
You should chagne some configuration.

1. in the project, you delete _MBCS and input _UNICODE.
 [Project] -> [Settings] -> [C/C++ tab] -> [General Category]
  in the Preprocessor definitions, change _MBCS to _UNICODE
2. If you meet "Cannot open MFC42ud.dll(mfc42u.lib, mfcs42d.lib, or etc)"
 Copy the MFC library to your local machine. 
 From CD \VC98\MFC\LIB\all files to \Microsoft Visual Studio\VC98\MFC\Lib\ directory
3. [Project] -> [Settings] -> [Link] 
 In the Object/libary modules, insert mfc42u.lib
And compile the source code.

If you will see "msvctl.lib:error LNK2001 :unresolved external symbol _WinMain@16~~~"
 [Project] -> [Settings] -> [Link] 
 In the Entry-point symbol set "wWinMainCRTStartup"

That's all.

Sunday, February 8, 2009

Helvetica

Documentary Helvetica

Helvetica A Documentary Film by Gary Hustwit
Helvetica Movie Clip

Wednesday, February 4, 2009

About Japanese animation

Nowadays I watched 2 animations ("anime" or "manga").

Time of Eve (イヴの時間)

Voices of a Distant Star (ほしのこえ)

Japanese animations have variety living thing, i.e. they treat many subject matters which I never think about before. In this reason I like "anime". And I want to learn Japanese.
Do you like Japanese animation?

Monday, February 2, 2009

Flash based web search engines

Flash based web search engines


1. Search engine with a touch of humor that plays prerecorded movie clips of a female actress to entertain you while searches are being performed:
2. Search for the most current political topics and election information at leftvsright.com. Stay informed on the presidential race, nominations, poll numbers, candidates and more:
3. Blinkx - World's largest video search engine. Search over 32 million hours of video from sites like Google Video, YouTube, MySpace, MetaCafe, and more:
4. Cannot access this site : 
5. RedZee is the result of many years of brain-storming sessions that aimed to create a search engine that will revolutionize search. Conventional search engines use text as the main focus of their results, only bringing back 10 results ... :
6. Preview web search results, watch videos, listen to music, find images, review news and find great shopping deals :