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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b5627b980414da76 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-03-15 04:18:06 PST Path: bga.com!news.sprintlink.net!cs.utexas.edu!math.ohio-state.edu!jussieu.fr!nef.ens.fr!sands From: sands@clipper.ens.fr (Duncan Sands) Newsgroups: comp.lang.ada Subject: Re: Higher precision and generics Date: 15 Mar 1995 12:12:38 GMT Organization: Ecole Normale Superieure, PARIS, France Distribution: world Message-ID: <3k6ljm$bhp@nef.ens.fr> References: <3jsnbf$ido@nef.ens.fr> <795197606snz@linkmsd.com> NNTP-Posting-Host: clipper-gw.ens.fr Date: 1995-03-15T12:12:38+00:00 List-Id: |>: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 Yes, and as Keith Thompson (The_Other_Keith: kst@thomsoft.com) pointed out to me, most Ada compilers only support either 32 or 64 bit floating point numbers, so doubling the number of digits would always require at least the maximum machine precision anyway. Dan Kurfis (dkurfis@enet.net) suggested taking the higher precision type as an additional generic parameter, which would increase the portability and flexibility of the package. Many thanks to you all for your help, Duncan Sands.