From: Matthias Teege <matthias@mteege.de>
Subject: exponentiation of fixed point or decimal
Date: 14 Dec 2000 19:24:53 +0100
Date: 2000-12-14T19:24:53+01:00 [thread overview]
Message-ID: <87hf46uah6.fsf@moon.mteege.de> (raw)
Moin,
I have a question about exponentiation of fixed point typs. The
following code didnt compile because of the '**' operator is not
defined for fixed point typs. So I made a lot of type conversions from
my fixed point type to float but the result for an Var_B of 10000
differs 0.01 of what my desk calculator says.
I have also made test with the numerics packages. If I use reals there
will be a better result but my "application" is for financial
transactions and I think fixed point or decimal is the best choice.
Is there any way for an exponentiation of fixed types?
procedure test is
Max_Delta : constant := 0.001;
Max_Digits : constant := 15;
type MyDec is delta Max_Delta digits Max_Digits;
package MyDec_IO is new Ada.Text_IO.Decimal_IO(MyDec);
Var_A: MyDec := 5.00;
Var_B: MyDec;
function myfunc(K: MyDec; Z: MyDec; Count: Positive ) return MyDec is
begin
return K * (1.00 + Z / 100) ** Count;
-- return MyDec(Float(K) * Float((1.00 + Z / 100)) ** Count);
end myfunc;
Begin
MyDec_IO.Get(Var_B);
MyDec_IO.Put(myfunc(Var_B, 5.00, 5), EXP=>0, FORE=>2, AFT=>2);
end test;
Many thanks
Matthias
--
Matthias Teege -- matthias@mteege.de -- http://emugs.de
make world not war
PGP-Key auf Anfrage
next reply other threads:[~2000-12-14 18:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-12-14 18:24 Matthias Teege [this message]
2000-12-16 1:31 ` exponentiation of fixed point or decimal Robert Dewar
2000-12-23 15:23 ` Mats Weber
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox