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 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: Simon Wright Subject: Re: fixed type (delta) in ada Date: 1999/11/30 Message-ID: #1/1 X-Deja-AN: 554974884 X-NNTP-Posting-Host: pogner.demon.co.uk:158.152.70.98 References: <383f6dbb.22609744@news.tstonramp.com> <384118EF.911A1ABB@callnetuk.com> X-Trace: news.demon.co.uk 943991186 nnrp-08:10947 NO-IDENT pogner.demon.co.uk:158.152.70.98 Organization: At Home Newsgroups: comp.lang.ada X-Complaints-To: abuse@demon.net Date: 1999-11-30T00:00:00+00:00 List-Id: Nick Roberts 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.