home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / ada / 3874 < prev    next >
Encoding:
Text File  |  1993-01-04  |  2.4 KB  |  67 lines

  1. Newsgroups: comp.lang.ada
  2. Path: sparky!uunet!seas.gwu.edu!mfeldman
  3. From: mfeldman@seas.gwu.edu (Michael Feldman)
  4. Subject: Re: Ada Readability, Book Reference
  5. Message-ID: <1993Jan4.174424.5699@seas.gwu.edu>
  6. Sender: news@seas.gwu.edu
  7. Organization: George Washington University
  8. References: <9212281507.AA20416@ajpo.sei.cmu.edu> <1992Dec30.035143.10291@seas.gwu.edu> <1993Jan4.093155.11894@nobeltech.se>
  9. Date: Mon, 4 Jan 1993 17:44:24 GMT
  10. Lines: 55
  11.  
  12. In article <1993Jan4.093155.11894@nobeltech.se> leeu@nobeltech.se (Leif Euren) writes:
  13. >
  14. [stuff deleted]
  15. >>
  16. >>In the specific case, (6.0 * 1.0)/3.0 can yield a different result from 
  17. >>6.0 * (1.0 / 3.0) because 1.0/3.0 cannot be exactly represented.
  18. >>Therefore an expression like
  19. >>  6.0 * (1.0 / 3.0) = (6.0 * 1.0) / 3.0
  20. >>may not evaluate to True. Traditional floating-point gotcha.
  21. >
  22. >Er... This is not a very good example. The constants used are of
  23. >universal_real type, and according to LRM 4.10(4) "... if a universal
  24. >expression is a static expression, then the evaluation must be exact."
  25. >
  26. >But if I write
  27. >
  28. >    B := 1.0;
  29. >
  30. >    if 6.0 * (B / 3.0) = (6.0 * B) / 3.0 then
  31. >
  32. >    else
  33. >
  34. >    end if;
  35. >
  36. >your arguments hold true.
  37.  
  38. Hmmm. How on earth could 1.0/3.0 be exact? What would the value be?
  39.  
  40. I checked my Annotated LRM (thanks to Karl Nyberg!) and found AI-00209:
  41. "An implementation can refuse to evaluate a static universal real expression
  42. only if there are insufficient resources to evaluate the expression exactly,
  43. e.g., if there is insufficient memory available. Inexact results must not
  44. be delivered."
  45.  
  46. This is interesting. I take it, then, that 1.0/3.0 will be flagged by
  47. the compiler, because - unless a rational representation is being
  48. used, which is always possible, I suppose - there aren't enough bits
  49. in a megabyte to evaluate it exactly. Do compilers use rationals
  50. for this?  I'll be back later, after a test or two of this!
  51.  
  52. Mike Feldman
  53. ------------------------------------------------------------------------
  54. Michael B. Feldman
  55. co-chair, SIGAda Education Committee
  56.  
  57. Professor, Dept. of Electrical Engineering and Computer Science
  58. School of Engineering and Applied Science
  59. The George Washington University
  60. Washington, DC 20052 USA
  61. (202) 994-5253 (voice)
  62. (202) 994-5296 (fax)
  63. mfeldman@seas.gwu.edu (Internet)
  64.  
  65. "Americans want the fruits of patience -- and they want them now."
  66. ------------------------------------------------------------------------
  67.