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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,560b069fa82486f6 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.germany.com!newsfeed.utanet.at!newsfeed01.chello.at!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Rounding with decimal types Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <13kjevsjmhujaa3@corp.supernews.com> Date: Mon, 26 Nov 2007 14:47:09 +0100 Message-ID: <1k7nof3469gt2.144br30askbb5.dlg@40tude.net> NNTP-Posting-Date: 26 Nov 2007 14:39:48 CET NNTP-Posting-Host: a89c8d73.newsspool3.arcor-online.net X-Trace: DXC=3h;Gjc@aX]4i6K;>iZ]763McF=Q^Z^V384Fo<]lROoR14nDHegD_]R5fookg2E=5^kAV?J]2 X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:18627 Date: 2007-11-26T14:39:48+01:00 List-Id: On Mon, 26 Nov 2007 08:15:02 +0000 (UTC), Wiktor Moskwa wrote: > I'd like to know if there is "round up" and "unbiased rounding" > implemented for decimal types in Ada and if not, how "is it usually done"? Yep, this is a problem, I faced it too but for floating-point numbers when implemented interval computations. There one needs rounding up and down as well. I would suggest something as clumsy as: -- Up-rounding multiplication function "*" (Left, Right : My_Decimal) return My_Decimal is type Impl is new My_Decimal; begin if Left = 0.0 then return 0.0; else declare Result : Impl := Impl'(Impl (Left) * Impl (Right)); begin if Result / Left /= Right then return My_Decimal'Succ (My_Decimal (Result)); else return My_Decimal (Result); end if; end; end if; end "*"; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de