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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ec3fa884e8653f90 X-Google-Attributes: gid103376,public From: "Samuel T. Harris" Subject: Re: Math Questions Date: 1999/06/03 Message-ID: <3756D10E.37CDA084@hso.link.com>#1/1 X-Deja-AN: 485365222 Content-Transfer-Encoding: 7bit References: <7ivc7m$q75$1@nnrp1.deja.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Raytheon Training Inc. Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-06-03T00:00:00+00:00 List-Id: dvdeug@my-deja.com wrote: > > I'm working on a number library for Ada, and I came across some > problems? > > (1)Is there any way of dealing with infinity in real numbers in Ada > (like IEEE's +INF)? In my bound float unit, it would be much nicer to > store it as between 1 and infinity than just throw a Constraint Error. > > (2)I'd like to create a IEEE745 type, but then you couldn't use it as > the base type for the bound float unit. Is there any way to make a type > look like a number to generics? If you custom type is some sort of record, then the answer is no. > > (3)Alternately, is there any way to make a generic package accept both > standard floats and any number-like types I create? Yes. Assuming you have created a custom record type encapsulating the structure of an IEEE745 type (whatever that is :) then you will need to define the operations and common attribute functions. generic type my_number_type is private; with function "+" (left, right : my_number_type) return my_number_type; -- similarly for all the predefined operators. with function image (item : my_number_type) return string; -- similarly for any attribute-like functions you may need package whatever is ... end; Because you can't force Ada to view your custom record type as a numeric type. Numeric types are predefined. However, a generic formal floating point type (fixed point or integer type for that matter) is a convenient notation which relieves the programmer from having to include all the predefined operations in the generic formal part. You can't take advantage of this notation because you have created what behave as a numeric, but is NOT a numeric type. Therefore you are stuck with expanding the generic formal part to include all the operations and attribute functions you generic requires. Such a generic formal part will work for both your custom type as well as the predefined numeric types, with the exception of the attribute functions. They require wrapper functions for the predefined numeric types. > > -- > David Starner - dstarner98@aasaa.ofe.org > > -- > David Starner - dvdeug@my-dejanews.com, dstarner98@aasaa.ofe.org, > dvdeug@hotmail.com > GURPS: http://w > > Sent via Deja.com http://www.deja.com/ > Share what you know. Learn what you don't. -- Samuel T. Harris, Principal Engineer Raytheon, Scientific and Technical Systems "If you can make it, We can fake it!"