Why is 0.1f + 0.2f - 0.3f produces such a large error number?

MarLOne <[email protected]>
Newsgroups gmane.comp.gnome.mono.general
Message-ID <[email protected]>
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:
public void Test()
{
    float delta = 0.1f + 0.2f - 0.3f;
    Console.WriteLine( "Delta is {0}", delta );
}

Since this is a floating point operation I do not expect that delta to be
absolutely zero. But I don't expect a number like this -7.450581E-09.

A similar test in C produces an absolute 0 even when it does not involve
static expression. 

Any comment or explanation?

Rover






--
View this message in context: http://mono.1490590.n4.nabble.com/Why-is-0-1f-0-2f-0-3f-produces-such-a-large-error-number-tp4667837.html
Sent from the Mono - General mailing list archive at Nabble.com.
_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.