Re: [Mono-list] Why is 0.1f + 0.2f - 0.3f produces such a large error number?

2016-05-23 Thread Alan
You really have two options: 1) Use float/double values and accept that you will get rounding errors in all trivial and/non-trivial floating point calculations. You will have to deal with this lack of precision appropriately for the type of calculation you are performing. This is not a bug, this

Re: [Mono-list] Why is 0.1f + 0.2f - 0.3f produces such a large error number?

2016-05-23 Thread MarLOne
Hi Alan, While all this is find it does not explain the following observation using the same CPU: VS2015 the delta is zero For all other VS dated back to 2003 the delta is non-zero. In fact my friend has shown me his code that led him to question this: He has a web server implementing that

Re: [Mono-list] Why is 0.1f + 0.2f - 0.3f produces such a large error number?

2016-05-17 Thread Timotheus Pokorra
> Does this mean one should not use C# when performing scientific > calculations? The above information is interesting. For financial calculations it is recommended to use System.Decimal I don't know about scientific calculations. Timotheus ___

Re: [Mono-list] Why is 0.1f + 0.2f - 0.3f produces such a large error number?

2016-05-17 Thread Alan
You could also google for discussions about adding 0.1 and/or 0.2 multiple times. That has fun results in every language too, for example http://stackoverflow.com/questions/26120311/why-does-adding-0-1-multiple-times-remain-lossless On 17 May 2016 at 13:23, Alan wrote:

Re: [Mono-list] Why is 0.1f + 0.2f - 0.3f produces such a large error number?

2016-05-17 Thread Alan
There's no reason you should not use it if the errors you are seeing are within the tolerance of floating point calculation limits. If you require more accuracy then use double instead of float. If you require perfect accuracy then you'll have to use a special type/library which provides more

Re: [Mono-list] Why is 0.1f + 0.2f - 0.3f produces such a large error number?

2016-05-17 Thread MarLOne
Thanks for the reply. The following disclosure may not have anything to do with explaining this but it highlights some inconsistency in .Net: I know Mono is not exactly VS (well very close as Xamarin is now part of Microsoft) but the following comparison is still valid and interesting: VS2003,

Re: [Mono-list] Why is 0.1f + 0.2f - 0.3f produces such a large error number?

2016-05-15 Thread Alan
At that level the rounding errors are down to how the compiler optimises the calculations, whether the calculations are performed as actual 32bit operations, or if they inflate to 64bit and then are rounded back to 32bit results, the order of the operations and the actual CPU instructions used to

[Mono-list] Why is 0.1f + 0.2f - 0.3f produces such a large error number?

2016-05-15 Thread MarLOne
Hi, I am using MonoDevelop 5.10 and the runtime Mono 4.2.3 (Stable 4.2.3.4/832de4b Wed Mar 16 13:19:08 UTC 20 in a Mint17 (64bit) environment. I am compiling the following code into .Net 4/4.5 and hence I believe I am using dmcs version 4.2.3.0 A friend posts me the following piece of code: