|
Loss of precision is an inherent problem with floating-point numbers (float and double ). You should never test for equality between two float s/double s because of this, but instead test that the difference is less than some threshhold.
To get around this, you'll need to use some alternate means of manipulating floating-point numbers.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
"Just because the box has 2 gigabytes of memory doesn't mean you get to use it all!"
-- Rico Mariani, CLR perf guy
|
|
|
|
|
Michael Dunn wrote:
you'll need to use some alternate means of manipulating floating-point numbers.
You right! But I'd like to know which one exactly. Some useful links are welcomed.
|
|
|
|
|
It would be wise to compare the result from above formula with result from
-s*ay - h*by + cy*(s+h)
and if results dont compare have some kind of error recovery. if calculations are not too many and time bound most wise programmers(not me) calculate with 2 formulae and compare results.
|
|
|
|
|
Mike is correct. However, there is something more going on.
Are you sure that "s == h"? Even with floating point imprecision, I don't see how the two parts of the expression won't cancel each other out. I tried this with initializing h and s to 1.0/3.0 and it worked properly.
However, generally speaking, checking for "== 0" with floating point numbers is a VERY bad idea. Usually you need to check if "- epsilon < x < epsilon" where epsilon is your tolerance for imprecision.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
You know, I'm not checking if h==s, I just execute the code.
I found out that h==s using debugger.
I'm interested in way to find out that precision lost occured in
MS VisualC++ 7.0.
|
|
|
|
|
Follow the link below, you will know why there is loss in precision:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_why_floating_point_numbers_may_lose_precision.asp
To solve the problem, there is a free library called MAPM which can help you to calculate precisly:
http://www.tc.umn.edu/~ringx004/mapm-main.html
Hope that it can help.
|
|
|
|
|
The problem solved itself!
I've changed computer (from Celeron 800 MHz to Celeron 2GHz),
and the equation doesn't affects the results!
Anybody knows the reason?
I heard something about bugs in FPU of P300-1000...
Anyway, thank you very much for links, Hing.
They are very useful for me.
|
|
|
|
|
Hi!
I'm looking for a special algorithm, either a one ready-to-use or at least a description of how to begin:
Say I have a image file (.jpg), I want to analyze what color/s has/have the biggest potion - say I have an image with many gray tones, then I want to get the RGB value of this gray color, or an average of the most used gray tones in the picture.
I hope my question was clear enough
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
The easiest way is to build a histogram - count how many appearances each color has.
|
|
|
|
|
why dont you add the r, g and b values of every pixel and compare the sum?
Don't try it, just do it!
|
|
|
|
|
There are some small programs of examining bitmaps at www.flounder.com, you'll need to convert them to .bmp first.
If nothing else, they may give you a good start.
Good luck!
INTP
|
|
|
|
|
Thanks, I will try some of your suggestions
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hallo!
I'm a beginner with MFC... can somebody tell me how can I read 3 parameters from a *.txt into a Class.
//actually it would be 3 points of an triangle and I would load the co-ordinates of Points from the file
<br />
typedef int Point[2];<br />
<br />
class Point : public CObject<br />
{<br />
public:<br />
<br />
<br />
Points(){};<br />
<br />
Pont SummPoints[5];<br />
int PointNumm;<br />
bool TriangleTest (Pont a, Pont b, Pont c) <br />
{<br />
double long1 = sqrt((a[0]-b[0])*(a[0]-b[0]) + (a[1]-b[1])*(a[1]-b[1]));<br />
double long2 = sqrt((a[0]-c[0])*(a[0]-c[0]) + (a[1]-c[1])*(a[1]-c[1]));<br />
double long3 = sqrt((c[0]-b[0])*(c[0]-b[0]) + (c[1]-b[1])*(c[1]-b[1]));<br />
if (long1>= (long2+long3)) return false;<br />
<br />
}<br />
};
Muad-Dib
mailto:adamo_piar@freemail.hu
Made in Hungary
|
|
|
|
|
do this :
<font style="color:blue;">int</font> i1, i2, i3;
ifstream my_file("c:\\folder\\my_file.txt");
my_file >> i1 >> i2 >> i3;
my_file.close();
according that your file look something like 125 21 31
TOXCCT >>> GEII power
|
|
|
|
|
Hello all,
Yet again another CPropertyPage question
I have these two propertypages which aren't identical but, however, contain some identical controls (that said, same message handlers and code).
So, instead of doubling my code by writing the same code in each CPropertyPage class I thought of two possibilities on how to only need to code it in one place (and hence making it easier to manage both pages):
1. Make an ordinary baseclass which both property pages derive from. Then each property page class has implemented the message handlers and simply call the base class' implementation.
2. Make a baseclass derived from CPropertyPage and implement message handlers for the shared controls. What I'm unsure about here, is if each property page knows how to correctly call the base class message handlers (is that even possible?).
Looking forward to some suggestions
|
|
|
|
|
Halloko wrote:
What I'm unsure about here, is if each property page knows how to correctly call the base class message handlers (is that even possible?).
the right base class will be called, you can put the common code in the base class derived from the CPropertyPage.
The common code should be generic and should not depend on specific propertypage control.
You need to handle the event in the derived class only and call the baseclass method that you have implemented to do the job that you want to do.
I dont know how much this would be applicable to you, but then i tried.
Regards,
I'll write a suicide note on a hundred dollar bill - Dire Straits
|
|
|
|
|
Mr.Prakash wrote:
You need to handle the event in the derived class only and call the baseclass method that you have implemented to do the job that you want to do.
So, what you're saying here is that I should have a base class which implements the different events but NOT the message handlers since each derived class should include those and then call the appropriate base class?
I was hoping it would suffice just to declare the message handlers in the base class and the framework would automatically route events to the base class without any work in the derived classes.
Did I understand you correctly?
|
|
|
|
|
Halloko wrote:
I was hoping it would suffice just to declare the message handlers in the base class and the framework would automatically route events to the base class without any work in the derived classes.
Technically,what you are trying to do, should work. But you might have one problem... Data Access.
Methods in the baseclass cannot access member variable in the derived class,
Plus for the events to work for the controls in both derived property page,they should have same IDC_XXX value.
I'll write a suicide note on a hundred dollar bill - Dire Straits
|
|
|
|
|
Mr.Prakash wrote:
But you might have one problem... Data Access.
Methods in the baseclass cannot access member variable in the derived class,
This shouldn't be a problem since, as I told you earlier, the controls are shared between both property pages and therefore have the same IDC_ etc.
Therefore the member variables for each control etc. will reside in the base class and not be specific to each page (that's the whole idea anyways )
So, you think this should be possible? Well, how about I have a go at it :p
|
|
|
|
|
Halloko wrote:
So, you think this should be possible? Well, how about I have a go at it
sure, I think you should try it out with one control only and understand all the complexity involved with the solution.
I'll write a suicide note on a hundred dollar bill - Dire Straits
|
|
|
|
|
The hWnd of the instance of my OCX Control is always 0x00000000! So I am unable to PostMessage() withing my control.
Nothing works... Even GetActualParent() as posted in the MSDN...
If anyone has encountered anything similar, or have an idea to get around this, please reply back as I'm stuck over this for more than 24 hours now! confused:
Thanks,
Nirav Doshi
|
|
|
|
|
I assume that you call GetsafeHWnd()in OnCreate(LPCREATESTRUCT lpCreateStruct) function or after it is called and not in Constructor as many times I do
|
|
|
|
|
Hi Pradeep,
Pradeep Maskeri wrote:
I assume that you call GetsafeHWnd()in OnCreate(LPCREATESTRUCT lpCreateStruct) function or after it is called and not in Constructor
Thanks for your reply!
My OCX is a wrapper for a hardware device - And doesn't need to create any window. So, I'm not handling WM_CREATE!
Now, if you make a similar OCX using MFC, and put it in a VB Form... Then try to debug the OCX code by making the VBClient.EXE with your OCX embedded in the VB Form, you can see that the OCX control's HWND is ALWAYS 0x00000000!
But if you insert the control in the ActiveX Test Container or another VC++ (MFC) client app, and then you debug your OCX code, you will see the OCX control's HWND has a legitimate value.
This is the problem, I have! (
- Nirav
|
|
|
|
|
Oh! It is windowless.
So this may help http://www.kbalertz.com/Feedback_153582.aspx
I hope sincerely
|
|
|
|
|
hi,
i am trying to retrieve user account information from the registry. Does any one know about any MFC or some other technique to get the users and their respective information like their account details, privilages etc.
thanks
|
|
|
|