comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Dewar <robert_dewar@my-deja.com>
Subject: Re: fixed type (delta) in ada
Date: 1999/11/28
Date: 1999-11-28T00:00:00+00:00	[thread overview]
Message-ID: <81pvi5$sl1$1@nnrp1.deja.com> (raw)
In-Reply-To: 383f6dbb.22609744@news.tstonramp.com

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.




  parent reply	other threads:[~1999-11-28  0:00 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-11-27  0:00 fixed type (delta) in ada Nap
1999-11-26  0:00 ` Al Christians
1999-11-27  0:00   ` fixed type (delta) in ada and GNAT bug David C. Hoos, Sr.
1999-11-28  0:00 ` fixed type (delta) in ada Nick Roberts
1999-11-30  0:00   ` Simon Wright
1999-11-28  0:00 ` Robert Dewar [this message]
1999-11-27  0:00   ` Al Christians
1999-11-28  0:00     ` Preben Randhol
1999-11-28  0:00     ` Florian Weimer
1999-11-28  0:00       ` Al Christians
1999-11-29  0:00         ` Preben Randhol
1999-11-29  0:00           ` Al Christians
1999-11-29  0:00             ` Preben Randhol
1999-11-29  0:00     ` Robert Dewar
1999-11-29  0:00       ` Al Christians
1999-11-29  0:00         ` Lutz Donnerhacke
1999-11-29  0:00           ` Preben Randhol
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox