From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Rounding with decimal types
Date: Mon, 26 Nov 2007 14:47:09 +0100
Date: 2007-11-26T14:39:48+01:00 [thread overview]
Message-ID: <1k7nof3469gt2.144br30askbb5.dlg@40tude.net> (raw)
In-Reply-To: fidva6$pkd$1@nemesis.news.tpi.pl
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
next prev parent reply other threads:[~2007-11-26 13:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-25 15:36 Rounding with decimal types Wiktor Moskwa
[not found] ` <13kjevsjmhujaa3@corp.supernews.com>
2007-11-26 8:15 ` Wiktor Moskwa
2007-11-26 13:47 ` Dmitry A. Kazakov [this message]
2007-11-26 14:55 ` Wiktor Moskwa
-- strict thread matches above, loose matches on Subject: below --
2007-11-26 12:27 Grein, Christoph (Fa. ESG)
2007-11-26 14:46 ` Wiktor Moskwa
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox