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,96daa6f775bc14b9 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-07-02 10:48:33 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!howland.erols.net!news-out.worldnet.att.net.MISMATCH!wn3feed!worldnet.att.net!135.173.83.71!wnfilter1!worldnet-localpost!bgtnsc06-news.ops.worldnet.att.net.POSTED!not-for-mail Message-ID: <3B40B485.F9E4074B@worldnet.att.net> From: James Rogers X-Mailer: Mozilla 4.76 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Generics??? References: <3B40F6BA.63A5C0FB@ida.his.se> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Mon, 02 Jul 2001 17:48:32 GMT NNTP-Posting-Host: 12.86.33.229 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc06-news.ops.worldnet.att.net 994096112 12.86.33.229 (Mon, 02 Jul 2001 17:48:32 GMT) NNTP-Posting-Date: Mon, 02 Jul 2001 17:48:32 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.ada:9338 Date: 2001-07-02T17:48:32+00:00 List-Id: Short answer: You can't. It would be a violation of Ada's strong typing. Integer types and float types are not implicitly convertable from one to the other. The problem is specifically the arithmetic operators for each type, as well as some of the attributes of each type. If you only want to compare values for equality, or assign one value to another, then you can specify the generic formal parameter to be private. If you want to perform arithmetic you must be specific about whether the type is a floating point type, a fixed point type, an integer type, or a modular type. Each type has its own definition of the arithmetic operators. The LRM does not require compilers to support ambiguity in the arithmetic operators for numeric types. In a language such as C++ the compiler would simply promote all integer types to doubles, perform the calculations, then (possibly) convert back to the template parameter's actual type. This is possible because C++ allows implicit conversion of all integer types to any floating point type. C++ also does not have an equivalent to Ada attributes. Many attributes of floating point types are not shared by integer types. Jim Rogers Colorado Springs, Colorado USA Michael Andersson wrote: > > Hi! > How do I specify that the generic parameter is a integer or a float. I > know that you can use > type T is range <> to specify that T is any Integer-type and that you > can use type T is digit <> to specify that T is any type of float. But > how can I use both at the same time? > I've tried to use type T is private but then I can't use any of the > +,-,*,/ operators. > > Need your help, please! > /Michael Andersson