|
Sakthi_Vel wrote: how do we do it?
You can't. Floating-point values cannot be represented exactly on a binary machine. Instead, you'll have to compare the difference to some very small number. For example,
if (fabs(Value1 - Value2) < 0.000001)
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
This is faster than my solution on any case, but... would it work using the function I wrote below rounding the decimals up to a Nth position?
Or will it give problems because of the internal structure of "double"?
I have just used my function to limit the numbers that had to be updated to the screen, due to place problems, not to do comparisons.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
But you are still comparing a double to 0.5 for equality.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Sakthi_Vel wrote: CString str1,str2;
str1.Format("%.3f",Value1);
str2.Format("%.3f",Value2);
Use %.3lf for double , f is for float .
Nibu thomas
MVP For VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http:\\nibuthomas.wordpress.com
|
|
|
|
|
Nibu babu thomas wrote: Use %.3lf for double, f is for float.
You might want to check the source code of CString::Format() . You'll find something to the contrary. The l prefix has an affect on d, i, o, x, X, u, c, C, s, and S types.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I made this function to use it in my project before doing updates from edits or labels
double CutAndRoundNumberToNDecimals (double dValue, const int nDec)
{ double dTemp = 0, dFract = 0, dInt = 0, dRes = 0;
dTemp = dValue*pow(10,nDec);
dFract = modf (dTemp, &dInt);
if (dFract >= 0.5)
dInt++;
dRes = dInt/pow(10,nDec);
return dRes;
}
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
I want to serach no of occrances for hex data in integer array .
suppsoe array is
usinged short int array[20] = {0xe1,0x33,044,0,0x33,0x34,0x32,0xed,0xe2,0x1,0x22,0x21,0x24,0x24,0xed,0xe2}
in above array i want to search 0xede2 and also how many time this value occurs in array and at what position. thanks
-- modified at 3:58 Friday 12th October, 2007
|
|
|
|
|
have you perfectly understod your own question?
you didnt specify, what the type, the array is.
and what do you refer it as HEX data.
what is the point in searching it.
explain clearly for us to solve your problem.
and make a note that,
when you are posting some thread, the subject line should be some thing relevant to your description.
"please help" makes no sense, coz,
see this on top of your page
"4,589,938 members and growing! 21,276 now online."
all of us are here only to help.
Suggestion to the members:
prefix your main thread subject with [SOLVED] if it is solved.
chandu.
|
|
|
|
|
Well, as you can easily see here [^] hex is only a numeral system, i.e. roughly speaking, a particular representation of a number. That stated, what do you need to do? Have you an array of binary (i.e. not-text, out of ASCII range) values? Or have you an array of characters representing hexadecimal numbers?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
You got short int s (signed BYTES ), and want to search an int in them?
Does casting to int and finding by a loop work?
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
1. take each unsigned short from the array.
2. take 2 var byte1 and byte2.
3. from each byte observe each of its nibbles.
4. if any nibble is greater than 9 then that element is your victim.
5. simple ,problem solved!
6. any more doubts?
Suggestion to the members:
prefix your main thread subject with [SOLVED] if it is solved.
chandu.
|
|
|
|
|
I have made a sdi application, in that i have made a worker thread(in main application class) in that i have used some api's. Now my problem is in some case a api is not passing the flow of control. In this case after 10 seconds i want to display a message and break the thread. I tried to use timer through SetTimer method but it was not applicaple because WM_TIMER message is not present.Now, how to solve this problem? Can anybody help me in this.
Thanks in advance
|
|
|
|
|
Hey,
You can use void sleep( long millis ) instead of using timer
Regards,
Pankaj Sachdeva
There is no future lies in any job but future lies in the person who holds the job
|
|
|
|
|
neha.agarwal27 wrote: Now my problem is in some case a api is not passing the flow of control
do you mean that, your control flow is not coming out of your api?
if that is so, then,
as you said, timer is not working,
you can initiate another thread and do your termination there after 10 seconds.
any more clarifications?
Suggestion to the members:
prefix your main thread subject with [SOLVED] if it is solved.
chandu.
|
|
|
|
|
can you explain me this through an example. I am not getting where to start a thread and how to apply your procedure
|
|
|
|
|
say your thread 1 is like this.
thread1<br />
{<br />
....<br />
....<br />
....<br />
....<br />
api1();<br />
....<br />
....<br />
....<br />
} if you feel that some times your control is not coming out of api1. right?
so, take a global variable,
say flag=0;
before api1, make flag=1;
and after api1 make it 0;
take another thread, say,
thread2()<br />
{<br />
int counter=0;<br />
while(1)<br />
<br />
<br />
{<br />
Sleep(1000);
if(flag==1)<br />
{<br />
counter++;<br />
if(counter>10)<br />
terminate thread 1.<br />
}<br />
if (flag==0)<br />
{<br />
counter=0;<br />
}<br />
}<br />
}<br />
<br />
}<br />
}
neha.agarwal27 wrote: I am not getting where to start a thread and how to apply your procedure
start it just after your main thread creation.
Suggestion to the members:
prefix your main thread subject with [SOLVED] if it is solved.
chandu.
|
|
|
|
|
your given code is working fine but now the problem is i am starting various number of same threads together(for example if i have to find html code of 20 websites same thread will be run together for 20 websites and i am synchronising them using critical section). so if i end my 1st thread in 2nd thread all processing will stop at once and i will not get output of left sites....So how to deal with it.
|
|
|
|
|
yah, got your problem.
then you must change your architecture, in such a way, that, the timeout monitor thread is not common for all the threads.
so implement as follows.
thread1()//this thread may be having somany instances
{
create thread2();//which monitors the thread 1 for the timeout value.
-------
------
--------
flag=1;
api1;
flag=0;
--------
}
thread2()
{
you try to frame this logic.
}
here, for each thread1, a child thread(thread2) is created, which monitors its parent's(thread1's) timeout, and kills it if it is not responding in a specified timeout, and also terminates itself.
Suggestion to the members:
prefix your main thread subject with [SOLVED] if it is solved.
chandu.
|
|
|
|
|
got it?
Suggestion to the members:
prefix your main thread subject with [SOLVED] if it is solved.
chandu.
|
|
|
|
|
i am still trying the method problem is not solved yet...
|
|
|
|
|
Hi,
I'm developing an application that displays for 96 dpi perfectly fine.
But it doesn't get automatically adjusted on an 480 x 640 TFT LCD.
There must be an easy way of including an API that can convert my current program to
support the high dpi without much effort.
I would appreciate if someone can provide a helping hand.
Additional info:
I have extracted some lines of code below from the stdafx.h :
#if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
#ifndef _DEVICE_RESOLUTION_AWARE
#define _DEVICE_RESOLUTION_AWARE
#endif
#endif
#ifdef _DEVICE_RESOLUTION_AWARE
#include "DeviceResolutionAware.h"
#endif
ttarantula
|
|
|
|
|
ttarantula wrote: I'm developing an application that displays for 96 dpi perfectly fine.
But it doesn't get automatically adjusted on an 480 x 640 TFT LCD.
Whats the Problem?
As a side note, Windows is completely broken and incapable to cope with higher resolution. (fixed-size icons, fixed-size system-font, font rendering works only for 96dpi etc)
Maybe you simply experience the brokenness of Windows here?
Complain to Microsoft and tell them to fix that in Vista2
(and while you're at it, also tell them to drop the DRM forcing people to stay with XP or even W2K)
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
The image I wish to display on Pocket PC LCD screen, appears in the middle of the screen.
And to be exact it takes up only half of the Pocket PC LCD screen width.
-- modified at 5:56 Friday 12th October, 2007
|
|
|
|
|
HAi .,
In my application i have included mq.h header file ...and also windows.h header file...but when i am compiling its throwing follwing Error
c:\program files\microsoft visual studio\vc98\include\mq.h(139) : error C2501: 'PROPID' : missing storage-class or type specifiers
I think some of the header files need to add...!
is any one knows pls reply me...
Born to win...!
|
|
|
|
|
Have you used "Include file to project..."?? Just putting the #include header.h may not be enough.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|