home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13575 < prev    next >
Encoding:
Internet Message Format  |  1992-09-13  |  1.3 KB

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