home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!pmafire!news.dell.com!swrinde!sdd.hp.com!wupost!waikato.ac.nz!comp.vuw.ac.nz!actrix!Bruce.Hoult
- From: Bruce.Hoult@bbs.actrix.gen.nz
- Newsgroups: comp.lang.c++
- Subject: Re: Need Help on trivial issue
- Message-ID: <1992Sep13.140619.23894@actrix.gen.nz>
- Date: 13 Sep 92 14:06:19 GMT
- References: <14497@goanna.cs.rmit.oz.au>
- Sender: Bruce.Hoult@actrix.gen.nz (Bruce Hoult)
- Organization: Actrix Information Exchange
- Lines: 16
-
- In article <14497@goanna.cs.rmit.oz.au> gtj@goanna.cs.rmit.oz.au (Glenn T Jayaputera) writes:
- > Hi, I need help on the following program. The problem I have is if I
- > input the value > 1.1 the string "Yahooo....." is only printed once.
- > I dont Understand why n==of only for a value of 0.5 not 1.0, 1.5, 2.0, etc.
-
- The problem is that 0.1 isn't exactly represented in the binary system
- -- it will actually be something like 0.00011001100110011... This
- means that when you add five of them together you will get something
- that would look like 0.4999999 (in decimal) instead of 0.5.
-
- The moral? *NEVER* expect the == comparison to work on floating point numbers.
- --
- Bruce.Hoult@bbs.actrix.gen.nz Twisted pair: +64 4 477 2116
- BIX: brucehoult Last Resort: PO Box 4145 Wellington, NZ
- "Cray's producing a 500 MIPS personal computer with 256MB RAM and 8 GB
- hard disk that fits in your pocket!" "Great! Is it PC compatible?"
-