|
John Simmons / outlaw programmer wrote: It seems to me that since I'm using the service from a Windows form app, I would have to encrypt outgoing data, and decrypt incoming data.
Thats all automatic if you use SSL. Just host any webservice on SSL, and connect!
John Simmons / outlaw programmer wrote: The thing is, I'm not sure what to use - WSE 3.0 or WCF.
That has nothing to do with encryption, WSE defines security.
|
|
|
|
|
Given the code:
static void Main(string[] args)
{
double d = 0d;
d += 0.0963d;
d += 0.0029d;
d += 0.0654d;
d += 0.0386d;
d += 0.0526d;
}
why would d = 0.25579999999999997 after the final addition?
|
|
|
|
|
I would guess that at least one of these numbers cant be expressed exactly in binary, leading to a loss of precision
A simplified example:
0.3
could be approximated as 1/4 + 1/8 (0.01 + 0.001)
= .25 + 0.125
which is 0.375 i.e. a loss of precision
Obviously the .Net framework will have a more complex floating point mechanism to allow more possible numbers, but hopefully you get my point that some floating point numbers are hard to express in binary without some loss of information.
To solve the problem you could perhaps multiply all your floating point numbers by something, add them together and then divide again later - this sometimes will give a more precise answer
for example:
0.3 + 0.3
Approximated to 0.375 + 0.375 = .75 rather then .6
But:
((0.3 * 10) + (0.3 * 10)) / 10
=
(3 + 3) / 10
= 6 / 10 = .6
Converted into bin: 0.11
(which again is a loss of precision, but less so)
Again as a disclaimer, the maths I am trying to use to explain is over simplified and .Net is more complex then this!
Hopefully that helps,
Chris
[Edit: to elaborate on my point here is some test code I just wrote:
int i = 0;
i += 963;
i += 29;
i += 654;
i += 386;
i += 526;
double x = (double)i / 10000;
However I also tried the example given in the OP, and got the correct answer with no precision loss - different OS or version of .Net perhaps...
]
modified on Thursday, September 4, 2008 9:00 AM
|
|
|
|
|
|
this because precision in double data type, if you want to show just 4 digit precision, d.ToString("N4) you will give what you want
dhaim
programming is a hobby that make some money as side effect
|
|
|
|
|
If you want better accuracy - use decimal instead of double.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
First, you don't need the "d" notation after the numbers (and you could initialize d like so: double d = 0.0; .
Next, floating point math is not precise. Since a CPU is inherently an integer processor, performing floating point math results in an approximation.
Try using decimal for the math, and then cast it to a double.
decimal d = 0.0m;
d += 0.0963m;
d += 0.0029m;
d += 0.0654m;
d += 0.0386m;
d += 0.0526m;
double d2 = Convert.ToDouble(d);
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
modified on Thursday, September 4, 2008 9:34 AM
|
|
|
|
|
John Simmons / outlaw programmer wrote: Next, floating point math is not precise. Since a CPU is inherently an integer processor, performing floating point math results in an approximation.
Floating point math is done natively on every x86 from the Pentium forward. The rounding problem comes entirely from converting from base 2 (internal representation) to base 10. More specifically .1 (.01, .001. etc) is a repeating decimal in base 2 and cannot be represented exactly. This makes it impossible for the general case of floating point math to be done without rounding errors due to conversion.
To see the conversion of .1 to a binary decimal search for "Or for example, 0.1" in this WP article.
http://en.wikipedia.org/wiki/Binary_numeral_system[^]
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
hello
tried to make a screencapture of a panel with controls on it and "connections" at the background (created using paint() procedure). DrawToBitmap does only the visible part of the panel, so i came up with the following code after a while. problem is that the invisible part of the panel turns up black in the resulting jpeg picture. Does anyone have any suggestions for me?
protected virtual void mnuRptClicked(object sender, EventArgs e)
{
this.AutoScrollPosition = new Point(0, 0);
int w = 0,h = 0;
foreach(Control c in this.Controls )
{
if(c.Left + c.Width > w) w = c.Left + c.Width + 100;
if(c.Top + c.Height > h) h = c.Top + c.Height + 100;
}
if(w == 0) w = this.DisplayRectangle.Width;
if(h == 0) h = this.DisplayRectangle.Height;
Bitmap b = new Bitmap(w,h);
Graphics bg = Graphics.FromImage(b);
int bgHdc = (int)bg.GetHdc();
SendMessage(this.Handle , WM_PAINT, bgHdc, 0);
SendMessage(this.Handle, WM_PRINT, bgHdc, (int)(
DrawingOptions.PRF_OWNED |
DrawingOptions.PRF_CHILDREN |
DrawingOptions.PRF_CLIENT)
);
bg.ReleaseHdc();
bg.Dispose ();
b.Save(Application.StartupPath + @"\captured.jpg", ImageFormat.Jpeg);
b.Dispose ();
}
|
|
|
|
|
|
PrintWindow only gives me the visible part of the panel, and it also gives me the scrollbars !
|
|
|
|
|
Sorry I didnt realise you were in a scrollable panel, I thought you were trying to print a window behind some other window, or off screen.
|
|
|
|
|
anyone else a suggestion?
|
|
|
|
|
Hello, i am having trouble with serial communication in C#. I have created a screen form and am trying to send and receive characters from a controller. I already have the controller programmed and it is working correctly. I can send and receive data using the windows terminal. But whenever i press a button on my form or controller keypad C# gives me the following error:
Cross-thread operation not valid: Control 'ekraan' accessed from a thread other than the thread it was created on.
I have little experience with C#, so any pointers on how to clear the error would be handy
Here is the code example:
//
TY
modified on Tuesday, September 9, 2008 3:52 AM
|
|
|
|
|
The error you are getting is related to the way that the serial port works. The DataReceived event is not raised on the main thread. In general, this is a good thing since it allows you to perform all the processing on the incoming serial data without blocking the UI thread. However as with all things multi-threaded, that means that you can no longer interact with controls directly from the event handler (or any other routines the handler calls). You will need to use this.BeginInvoke to get back to the main thread.
public void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string strResult = sp.ReadExisting();
ekraan.Text += strResult;
}
becomes:
public void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
this.BeginInvoke(new Action<string>(UpdateData), sp.ReadExisting());
}
private void UpdateData(string message)
{
ekraan.Text += message;
}</string>
|
|
|
|
|
Thx for replying.
However, i now get the following error:
No overload for 'UpdateData' matches delegate 'System.Action'
It says that the erroneus part is that: new Action (UpdateData)
Do i need do declare some additional "system.######" -s?
TY
|
|
|
|
|
see this link[^]
dhaim
programming is a hobby that make some money as side effect
|
|
|
|
|
I mistyped that line. It should be:
this.BeginInvoke(new Action<string>(UpdateData), sp.ReadExisting());
|
|
|
|
|
Thanks
|
|
|
|
|
Ok, i am still having some trouble with the code. I have a controller on the other side with a thermometer and keyboard etc.
I am sending the temperature from there to my form. It normally works fine.
The only time it gives me an error is when the first thing i do is click "show temperature" on my screen form. Then the error that occours is the following:
Invoke or BeginInvoke cannot be called on a control until the window handle has been created.
If the first button i press is not "show temperature" then it works fine. I have a keyboard on screen as well.
Could it be that the forst time data is in some kind of wrong format? How to make sure that the window handle will be created before BeginInvoke?
Sample code:
... }
modified on Thursday, November 13, 2008 6:31 AM
|
|
|
|
|
It also says the following:
Target InvocationException was unhandled.
Exception has been thrown by the target of an invocation.
|
|
|
|
|
Hi,
I have some class libraries, which I dont want the client to use.
How can we secure our dll in such a way that if someone else adds our dll to his project then it gives some error or may e do not allow to add it.
|
|
|
|
|
|
i wrote a simple server that sends it's public key to the client using (RSACryptoServiceProvider),
rsa.ToXmlString(false) . at client it creates an xml file. i want the client to read the xml file and get the key.
I'm expecting support
|
|
|
|
|
prasadbuddhika wrote: i want the client to read the xml file and get the key
If its sent as an xml file you can read it as such.
prasadbuddhika wrote: I'm expecting support
Thats a bit rude - heard of a little word called PLEASE?
Bob
Ashfield Consultants Ltd
|
|
|
|