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

MarLOne InfoSeeker002 at gmail.com
Sun May 15 12:02:14 UTC 2016


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.


More information about the Mono-list mailing list