|
Dear experts
I'm migrating some stuff from c++ (Borland Builder) to c#.
While comparing the calculations between the two implementations I found among others
a.) c++: pow(0.1, 3.0) results in 0.001
b.) c#: Math.Pow(0.1, 3.0) results in 0.0010000000000000002
Ok so far so good. "power" is not an fpu instruction and therefore I can imagine that the two results are slightly different, because of maybe different implementation of the "power" function.
Nevertheless I made the following experiment
c++: double test= 0.1 * 0.1 * 0.1 which results in 0.001
c#: double test= 0.1 * 0.1 * 0.1 which results again in 0.0010000000000000002
Surprising for me
The latter now is something surprising -at least for me- because I'm assuming that both (c++ and c#) will use the fpu for multiplications.
I googled a lot for this, but I'm not able to find an explanation. Do you have an idea?
Thank you very much in advance for your comments on this.
Regards
[edit]
Btw: I also tried _clearfp and _fpreset for c#, but results remain the same.
It does not solve my Problem, but it answers my question
modified 19-Jan-21 21:04pm.
|
|
|
|
|
The default precision to which doubles are printed is different in C++ and C#, so they might actually be the same, can't tell from this. They might also be different, depending on some funny combination of one program being 32bit (and defaulting to the x87 FPU and 80bit computation followed by a conversion to 64bit) and the other 64bit (and defaulting to SSE2 and 64bit computation), I'm not sure if that actually makes a difference here.. If you reinterpret the bits as an int64 and print that we could be sure.
|
|
|
|
|
|
0x01AA wrote: I think ten years ago I would also have come up with the idea to compare the results binary
Also, the neatness the C++ result would have made a ring bell[^].
|
|
|
|
|
Thank you very much for this great link
It does not solve my Problem, but it answers my question
modified 19-Jan-21 21:04pm.
|
|
|
|
|
Makes me think of when I was playing around with APL: No distinction between int and float, no explicit declaration of type. All numerics were 64 bit FP.
To avoid problems with values that conceptually are the same, but due to limited precision may not be (such as 1/3 + 1/3 + 1/3 not necessarily being identical to 1.0), there was a user settable tolerance variable - if my memory is right, it was called quadFUZZ): In any comparing of numerics, if the difference was less that FUZZ, the values were treated as exactly equal. I believe something similar also exist in other highly environments, such as Smalltalk.)
I was teaching C++ programming for a few years. Any hand-ins where float variables were compared by == to constants or othter varibles did not pass. My teaching was to consider == an invalid operator for floats - use >, >=, <, <=. And where appropriate, code the APL style in longhand: if (abs(f1-f2) < fuzz) { ... treat as exactly equal.
Of course some students objected: "Why can't we just ...", and I had to explain over and over. One student went as far to hand in a homework which stared with a big block comment, headed by: "This is how REAL PROGRAMMERS would code the solution: ..." and after som real dirty code, at the end of the comment block: "But this is how our professor forces us to do it: " - and then some clean and readble code, not commented out. So he knew how to behave in a disciplined way, but refused do give up his undisciplined behaviour completely.
|
|
|
|
|
Thank you for your reply. But I was never trying to do something like a==b, I was comparing the two implementations.
Btw:
I would never do a==b for double values, instead I do !(a<b) && !(a>b) And no, of course I also don't do that
It does not solve my Problem, but it answers my question
modified 19-Jan-21 21:04pm.
|
|
|
|
|
Back in the day, I wrote a method called AlmostEqual to compare floating point values to a specified precision. I've found that as long as you don't do math on the value, it will remain as it was set, so given the following:
double x = 0.01d;
double y = 0.01d; The expression if (x == y) will always evaluate to true.
However, if you to this:
x = x * 1.0d the expression above will evaluate to false.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Thank you for your feedback.
double x = 0.01d;
double y = 0.01d;
bool equal = x == y;
x = x * 1.0d;
equal= x== y;
Both "x==y" above give true for me.
It does not solve my Problem, but it answers my question
modified 19-Jan-21 21:04pm.
|
|
|
|
|
Hey!
I have an excel file that I've already read and one of the column - lets call that: x - includes lots of data.
The python code that extracts the ids is: x.str.extract(D(?:H){0,1}[0-9]{1,2}) needs to be written in c# but I just can't get it to work.
Every little help is appreciated!
|
|
|
|
|
Just to clarify, you're only testing that a value between D0 to DH99 exists? If so, then the pattern is:
var regex = new RegEx(@"D(?:H){0,1}[0-9]{1,2}");
var match = regex.Match(x);
if(match.Success){
}
If you're trying to do something different you'll need to modify the regex and the access strategy.
"Never attribute to malice that which can be explained by stupidity."
- Hanlon's Razor
|
|
|
|
|
|
I have a comboBox which select a ID from a database. I want to get back another data from database depending on the ID. How can I do this?
First of all, a database should be visualized. Suppose you have a database like this
Member ID Amount Balance Input Date<br />
Now when I input the Member ID I want to get back the latest balance from that specific member using this query below.
"select * from [Interest Posting] where [Input Date] = (select max([Input Date]) from [Interest Posting]) and [Member ID] ='" + cb_MemberID.SelectedValue + "'";
But my problem is when I put the code for getting back the latest balance when there are two member ID's the value doesn't get changed. Why?
Feel free to ask for any clarification you might need for answering my question.
|
|
|
|
|
|
Thanks for the reply but the MemberID in the parameterized query needs
cb_MemberID.selectedValue to be supplied. The problem is this comboBox is being populated by another database & corresponding code.
This populating code is given in the
form_load event but the I am getting
value not supplied error.
Here is the code I am using for populating the cb_MemberID comboBox
string query2 = "select * from [Member Registration]";
con.ConnectionString = global::#connectionstring;
SqlCommand com1 = new SqlCommand(query2, con);
con.Open();
SqlDataAdapter adp1 = new SqlDataAdapter(com1);
DataTable dt1 = new DataTable();
adp1.Fill(dt1);
cb_MemberID.ValueMember = "ID";
cb_MemberID.DisplayMember = "MemberName";
cb_MemberID.DataSource = dt1;
con.Close();
|
|
|
|
|
Hi,
is this a WinForms application?
is the ComboBox using data binding?
which event are you using, and what's inside its handler (please show relevant code).
have you looked at the actual SQL command when it works and when it fails?
are you using try/catch blocks which do actually catch and show exceptions?
did you single-step with the debugger?
and/or possibly read ComboBox SelectedItem, SelectedValue, SelectedWhat??? – jaredpar's WebLog[^]
|
|
|
|
|
Hi,
i want to resize (Readjust) all of the controls that are belongs to a Form or User Control while i am resizing the User Control or the Form. I already have used from both docking and anchoring , but non of them are working properly. Is there any way to create a class to overcome this. i also searched but i did not get any proper answer.
i will be thankful if you professionals coach me to do it.
Thank you in advance.
|
|
|
|
|
That depends one what controls you are using, and what you consider "working properly" - you will have to describe what you have done (with a tiny example if possible) and what it did that you didn't want.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi, thank you for your help. when i use from anchor, during resizing, all controls take place on or below each other. i also chenged their autosize to false but the problem is still exists.
|
|
|
|
|
No, that doesn't make any sense.
Stop trying to type as little as possible and explain in detail, remembering that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
So we have no idea what anchor settings you used, or how your controls are arranged to start with - we don't even know if "resize" means your form "getting bigger" or "getting smaller"; "taller", "shorter", "both"; all of the above!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi,
excuse me, you're right. i am using c# and winApp. i want to change controls of a form or an user control in the same time with resizing the form or user control with mouse down movment in any direction (N,E,WS,NE,NW,SE,SW) and also with minimizing the and maximizing the form or user control. thank you for you help.
|
|
|
|
|
So you're not listening to a word I say, just posting no information?
Is there any point in trying to ask a question if you can't be bothered to tell us what we need to know?
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi,
Excuse me if i did not ask my question properly.
i only want to know is it possible to create a class to resize controls belong to a parent while i am resizing my parent (Form or user control)?
because when i am using from anchoring and docking in the controls properties, sizes are will changed but the controls will go under/Over each other.
i do not know what else shall i post!
Thank you for your kindly trying to help me .
|
|
|
|
|
If you're looking to create a class to handle this for you, that's not going to work.
You've simply got more learning to do to properly handle setting up your layouts with TableLayoutPanel, FlowLayoutPanel, Docking, Anchoring, any other containers, ...
It's not a simple "Ask a question and get an answer that will fix everything". The only answer to this problem is more learning and experimentation.
We can't see your layout and screen shots isn't going to help that because we also cannot see the properties of your controls and containers.
|
|
|
|
|
You have to set up an event handler for the form's size changed event, and iterate all of the controls you want to resize.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|