home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.ada
- Path: sparky!uunet!seas.gwu.edu!mfeldman
- From: mfeldman@seas.gwu.edu (Michael Feldman)
- Subject: Re: Ada Readability, Book Reference
- Message-ID: <1993Jan4.174424.5699@seas.gwu.edu>
- Sender: news@seas.gwu.edu
- Organization: George Washington University
- References: <9212281507.AA20416@ajpo.sei.cmu.edu> <1992Dec30.035143.10291@seas.gwu.edu> <1993Jan4.093155.11894@nobeltech.se>
- Date: Mon, 4 Jan 1993 17:44:24 GMT
- Lines: 55
-
- In article <1993Jan4.093155.11894@nobeltech.se> leeu@nobeltech.se (Leif Euren) writes:
- >
- [stuff deleted]
- >>
- >>In the specific case, (6.0 * 1.0)/3.0 can yield a different result from
- >>6.0 * (1.0 / 3.0) because 1.0/3.0 cannot be exactly represented.
- >>Therefore an expression like
- >> 6.0 * (1.0 / 3.0) = (6.0 * 1.0) / 3.0
- >>may not evaluate to True. Traditional floating-point gotcha.
- >
- >Er... This is not a very good example. The constants used are of
- >universal_real type, and according to LRM 4.10(4) "... if a universal
- >expression is a static expression, then the evaluation must be exact."
- >
- >But if I write
- >
- > B := 1.0;
- >
- > if 6.0 * (B / 3.0) = (6.0 * B) / 3.0 then
- >
- > else
- >
- > end if;
- >
- >your arguments hold true.
-
- Hmmm. How on earth could 1.0/3.0 be exact? What would the value be?
-
- I checked my Annotated LRM (thanks to Karl Nyberg!) and found AI-00209:
- "An implementation can refuse to evaluate a static universal real expression
- only if there are insufficient resources to evaluate the expression exactly,
- e.g., if there is insufficient memory available. Inexact results must not
- be delivered."
-
- This is interesting. I take it, then, that 1.0/3.0 will be flagged by
- the compiler, because - unless a rational representation is being
- used, which is always possible, I suppose - there aren't enough bits
- in a megabyte to evaluate it exactly. Do compilers use rationals
- for this? I'll be back later, after a test or two of this!
-
- Mike Feldman
- ------------------------------------------------------------------------
- Michael B. Feldman
- co-chair, SIGAda Education Committee
-
- Professor, Dept. of Electrical Engineering and Computer Science
- School of Engineering and Applied Science
- The George Washington University
- Washington, DC 20052 USA
- (202) 994-5253 (voice)
- (202) 994-5296 (fax)
- mfeldman@seas.gwu.edu (Internet)
-
- "Americans want the fruits of patience -- and they want them now."
- ------------------------------------------------------------------------
-