comp.lang.ada
 help / color / mirror / Atom feed
From: davea@linkmsd.com (David Arno)
Subject: Re: Higher precision and generics
Date: Tue, 14 Mar 1995 16:13:26 +0000
Date: 1995-03-14T16:13:26+00:00	[thread overview]
Message-ID: <795197606snz@linkmsd.com> (raw)
In-Reply-To: 3jsnbf$ido@nef.ens.fr

In article <3jsnbf$ido@nef.ens.fr> sands@clipper.ens.fr "Duncan Sands" writes:

: I am writing a package of matrix routines (in Ada!) in which some intermediate
:  results
: should be calculated in higher precision than normal.  The type for normal
:  precision is
: called Real and is a generic parameter of my package:
: generic
:    type Real is digits <>;
: package Matrix_Stuff is
:    ...
: end;
: 
: In the body I would like to be able to declare Double to be a higher precision
: floating point type, something like:
: package body Matrix_Stuff is
:    type Double is digits 2*Real'Digits;
:    ...
: end;
: 
: Unfortunately, this does not compile: apparently formal types like Real are not
: considered static, so Real'Digits is not considered static, and only static
: expressions are allowed in a "type X is digits expression" declaration.  (If
: I write "type Double is digits 2*Float'Digits" then it compiles fine).
: 
: What can I do to get type Double to be of higher precision than Real?
: Can anyone please help?  And does anyone know why formal types like Real are not: considered static?
: 
: Thanks a lot,
: 
: Duncan Sands.
: 

Probably the best thing to do in this situation is to declare a type within
the package body which has the highest precision possible:

	type Max_Precision_type is digits System.Max_digits;

and to use that internaly. Even if there were a way of overcoming the need
for the expression after digits to be statis, the concept of your internal
one always being double the precision of the parameter type falls down if
an instance of the package is declared using any type where the number of
digits is greater than half the maximum.

Hope this helps,
-- 
David Arno



  reply	other threads:[~1995-03-14 16:13 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-03-11 17:41 Higher precision and generics Duncan Sands
1995-03-14 16:13 ` David Arno [this message]
1995-03-15 12:12   ` Duncan Sands
1995-03-17  8:36     ` Dan Kurfis
1995-03-17 12:37       ` Peter Hermann
1995-03-19  1:23         ` Robert Dewar
1995-03-20 16:33           ` Peter Hermann
1995-03-21 21:14             ` Robert Dewar
1995-03-18  1:45       ` Keith Thompson
1995-03-20  9:05       ` dkurfis
1995-03-15 15:36 ` Mats Weber
1995-03-15 16:35   ` Peter Hermann
replies disabled

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