comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pogner.demon.co.uk>
Subject: Re: fixed type (delta) in ada
Date: 1999/11/30
Date: 1999-11-30T00:00:00+00:00	[thread overview]
Message-ID: <x7vbt8b4w75.fsf@pogner.demon.co.uk> (raw)
In-Reply-To: 384118EF.911A1ABB@callnetuk.com

Nick Roberts <nickroberts@callnetuk.com> writes:

> Nap wrote:
> > 
> > does anyone know why mutiplication between fixed type in ada produce a
> > big round off error?
> > ...
> 
> Do you want the short answer or the long answer, Nap?
> 
> The short version of the long answer is: the 'small' chosen for the type
> 'money' will be a power of two (e.g. 1/128); 0.20 will therefore not
> have an exact representation when converted to the type 'money'; this
> inexact representation of 0.20 will therefore produce an inexact result
> after multiplication.
> 
> The short version of the short answer is: use a decimal type instead of
> a fixed type (example follows).
> 
>    type Money is delta 0.01 digits 11;
> 
> Problem solved.

Alternatively,

  Money_Small : constant := 0.01;
  type Money is delta Money_Small range 0.0..100_000_000.00;
  for Money'Small use Money_Small;

gives the expected result for the case in question.




      reply	other threads:[~1999-11-30  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 Robert Dewar
1999-11-27  0:00   ` Al Christians
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-28  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
1999-11-28  0:00 ` Nick Roberts
1999-11-30  0:00   ` Simon Wright [this message]
replies disabled

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