ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i have a question ?
how can i know with which constructor a specific object was created .. i mean which constructor within the class(in case there are more than one ) had initialise the object i have ??
-- i do know that the object i have is instaceof class X for example , but what i ask is within class X which constructor built it .. ?
-- i am using java ..!
I don't know of a way to find that out unless you put the clue in the constructor itself, that is you have a property which each constructor would set to different values.
well , this is exactly the problem i face , since i use doubles , and using '==' is problematic , and the EPSILON to use inorder to determine wither two doubles are equals : |d1-d2|<EPSILON
is the parameter i initialise at the constructor ...
it's simple code ... but in order to implement the equals () method ( it's defined true iff the two objects were created by the same constructor with the same _precision)
the point is that i can't check wether ... |EPSILON - EPSILON|<EPSILON ..???!!!
hope that it's clearer now , thanks alot ,
m-s
graeme has a good point... the approach i also would take would be to put a flagg in the class.. i do not know of any other way to find out which constructor was called after the control has returned from the constructor.. though i am no java expert, but i still dont see this being possible.. here is a rough idea..
the point is that i can't check whether ... |EPSILON - EPSILON|<EPSILON ..???!!!
I think you want.
Code:
|d1-d2|<EPSILON
where d1 and d2 are objects of double.
If EPSILON is always a fixed value then I would make it static so that you have the same value for every instance of double. If not then you will need to make a decision on which EPSILON to use, I would guess that the double to the left of the operation would make sense, hence
Code:
double d1(56.5, 0.5);
double d2(56.0, 0.25);
...
d1.equal(d2); // would use EPSILON .5 and equate to true
d2.equal(d1); // would use EPSILON .25 and equate to false
Well the idea was that the first argument was the actual value whilst the second argument was the epsilon value. This only necessary if the epsilon value may change and it could be defaulted to a fixed value. Also the actual values I used are not very good ones! You would want the epsilon to be much smaller in relation to the magnitude of the actual number.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.