|
This is due to floating point precision. See here[^] (or google for it) for more information. If you really need more precision, you can always use a double (but I doubt that you need it).
|
|
|
|
|
Welcome to floating point math! Your result is typical and is why the #1 rule on doing floating point math is to never depend on the value being exact. You will need to compensate or use a higher precision number type, depending on what you are trying to accomplish.
In most situations the difference in calculated values is not significant, but sometimes it is. The worst resolution problems usually occur when you subtract 2 numbers that are close, then do further manipulations. If you are checking the value with if statements, for example, then you need to check that the value is within a reasonable tolerance.
Search around using Google and Bing for "floating point precision" and you should find lots of information.
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
Read here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Wow! Fantastic article: even those who already know the topic should read (and learn) it!
|
|
|
|
|
|
Hi, I am using HtmlHelp api to display help window in my
project.
HtmlHelp(hWnd, File Name, HH_HELP_CONTEXT, Id);
I have a Parent Dialog contains some controls. Whenever I press a
help button, help window should be opened.
After opening the help window, I am able to interact with the Parent Dialog.
But the problem is, the help windopw is still on the top of the parent dialog.
I want to push the help window behind Parent Dialog whenever I interact with
the Parent Dialog.
Please throw some ideas.
Regards
msr
|
|
|
|
|
msr_codeproject wrote: But the problem is, the help windopw is still on the top of the parent dialog.
I want to push the help window behind Parent Dialog whenever I interact with
the Parent Dialog.
It sounds to me like you want to change the window Z-Order[^] and remove the HWND_TOPMOST flag. The SetWindowPos Function[^] can do that for you. Something like:
SetWindowPos(YourHelp->hWnd, HWND_NOTOPMOST, 0, 0 , 0 , 0, SWP_NOMOVE | SWP_NOSIZE);
Best Wishes,
-David Delaune
|
|
|
|
|
I am developing a SDI application. When I change anything in .rc file, like add string in string table, add entry in accel table, I get error in compilation "error RC2135 : file not found: 0".
How can I resolve this issue?
|
|
|
|
|
Are you editing the rc file manually ? You shouldn't do it.
|
|
|
|
|
Well, unless you know what you're doing...
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Yes, which doesn't seem to be the case for the OP, since he's getting that error
|
|
|
|
|
Post the .rc entries here to show what you have changed.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Hi all,
i m using CreateFile to access com port,
i want to use this port at same time by the diffrent thread.
currently in my application if i run 5 threads than only any one is able to read this other return the error of Invalid Handle or Paramete is incorrect.
please help me how can i do this.
thanks in advance.
|
|
|
|
|
You can't do something like that. Furthermore, it is almost impossible to manage: suppose that a thread starts to read a couple of bytes, then another thread comes in and read another couple of bytes: how will you manage such a situation ?
What you can do however, is have one thread that reads the port and sort the information for the different threads to process: there's one buffer for each thread processing data and the thread which reads from the port puts the data in the appropriate buffer (and signal the processing thread that data is available).
Anyway, for which reason do you need to have multiple threads accessing the port ?
|
|
|
|
|
can u please explain me it with example,
|
|
|
|
|
It is very difficult to provide an example since we don't have any clue about your application. Where are you stuck exactly ?
|
|
|
|
|
actually i m sending sms using com port.
mobile connected with machine ,than if application run more than 1 thread and all wants to access this port to send sms,now the problem occur here.
|
|
|
|
|
You should serialize com port access: i.e. each thread may post a new sms message in a queue and then, the 'transmitter' thread will get messages from the queue and send them on the serial port.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Ok, it is for writing the port, not reading the port then. In that case, I think it is a bit more easier. Anyway, you still need to same principle: the thread that writes to the port creates a queue in which the other threads can push their messages. The access to the queue is protected by critical sections, so that multiple threads cannot write data at the same time in the queue.
To make things a bit easier, you will first need to wrap the SMS data into a specific class (makes it easier to manipulate). Then, you will need to create the queue class: to make things a bit more simple for now, this queue wraps a std::queue with the type of your SMS class. You'll then need to secure the access to the internal queue by using critical section.
After a bit of googling, I found this implementation[^] of a thread-safe queue. Try to understand the code first, then come here and ask specific questions about which part you didn't understand. Then, once you really understood how the code work, you can implement your own version of the queue.
|
|
|
|
|
Actually, I suppose, you can (different threads of the same process). However I agree with you on the 'design philosophy'.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
in my MFC Dialog based application ,i have a list box which contains list of text files with their full file paths. I also have edit box in my MFC application, now i want to display the contents of the file(selected from the list box)into the EditBox. in short i want to open the file in that edit box.... can n e buddy help me out!!!
modified on Monday, November 15, 2010 1:55 AM
|
|
|
|
|
It looks straightforward to me: what's your trouble about?
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CStdioFile Class
CEdit::SetWindowText
|
|
|
|
|
Hi all,
i am using ReadDirectoryChangesW synchronously to monitor a Drive...when ever any file is copied the same is validated and deleted if the file fails the validation check..and the loop continues its wait for next change on the directory monitored...however, when i copy a folder there is an issue..if the folder is invalid and deleted, then the code exits out of the loop of monitoring the directory....i am using recursive deletion to delete folders which are found invalid......
please could i get some help on how to fix this issue......
|
|
|
|
|
Without seeing your code it is impossible to guess what your program is doing. Please edit your message and add the relevant part(s) of your program, and don't forget to use the code block button to surround the code with <pre></pre> tags, to help readability.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|