comp.lang.ada
 help / color / mirror / Atom feed
* exponentiation of fixed point or decimal
@ 2000-12-14 18:24 Matthias Teege
  2000-12-16  1:31 ` Robert Dewar
  2000-12-23 15:23 ` Mats Weber
  0 siblings, 2 replies; 3+ messages in thread
From: Matthias Teege @ 2000-12-14 18:24 UTC (permalink / 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




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2000-12-23 15:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-12-14 18:24 exponentiation of fixed point or decimal Matthias Teege
2000-12-16  1:31 ` Robert Dewar
2000-12-23 15:23 ` Mats Weber

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