This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Floating point computation "non-bug"


Dave Elcock <dave at sias dot com> writes:

|> Simply compiling with 'gcc test.c' and then running './a.out 2.3' gives
|> the following output:
|> 
|> f1              2.300000
|> f2              23.000000
|> (int)f2         23
|> (int)(f1*10.0)  22
|> 
|> 
|> I can't see how such a simple example should be affected by floating point
|> precision.

Of course it can.  2.3 cannot be represented in base-2 floating point, so
what you have in f1 is not 2.3, but something close.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab at suse dot de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]