From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=BAYES_00,INVALID_MSGID, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b257fba0affa289 X-Google-Attributes: gid103376,public From: Robert Dewar Subject: Re: fixed type (delta) in ada Date: 1999/11/28 Message-ID: <81pvi5$sl1$1@nnrp1.deja.com>#1/1 X-Deja-AN: 553883865 References: <383f6dbb.22609744@news.tstonramp.com> X-Http-Proxy: 1.0 x43.deja.com:80 (Squid/1.1.22) for client 205.232.38.14 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Sun Nov 28 01:12:38 1999 GMT X-MyDeja-Info: XMYDJUIDrobert_dewar Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.04 [en] (OS/2; I) Date: 1999-11-28T00:00:00+00:00 List-Id: In article <383f6dbb.22609744@news.tstonramp.com>, nap@nobody.com (Nap) wrote: > does anyone know why mutiplication between fixed type in ada produce a > big round off error? > > type money is delta 0.01 range 0.0..100_000_000.00; > a, b, c : money; > > package money_io is new ada.text_io.fixed_io(money); > > a := 351.00; > b := 0.20; > c := a * b; > > money_io.put(c); > > -- the output should be 70.2 but it prints 71.3 instead. > -- this is so frustrating. typecasting (back to float) doesn't help > either. No, the output should be 71.3, and this is what is expected. You used a binary fixed point type, so you are working with binary numbers not decimal numbers. You need to read up more on the details of how fixed point works, or indeed you will frustrated yourself! Most likely you should be using decimal types (look up decimal types in the RM or in any good Ada text book). Sent via Deja.com http://www.deja.com/ Before you buy.