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,c7637cfdf68e766 X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: floating point comparison Date: 1997/08/02 Message-ID: #1/1 X-Deja-AN: 261848423 References: <33DF6F43.6EEA4806@digicomp.com> <5rqehs$g1r$1@odin.cc.pdx.edu> <33E11967.4A30@nr.net> <33E214C3.311C@pseserv3.fw.hac.com> Organization: Estormza Software Newsgroups: comp.lang.ada Date: 1997-08-02T00:00:00+00:00 List-Id: In article , dewar@merv.cs.nyu.edu (Robert Dewar) wrote: >In my view, no one who does NOT have this level of knowledge should ever >use the keyword digits in Ada (unless associated with delta), or use >the built in Float types! Perhaps so, but if you're writing an application that uses real numbers, then I assume your admonishment not to use floating point types means "use fixed point types" or "use floating point types, but take a class in numerical analysis first." You must admit that using a fixed point types in Ada 83 was sometimes a pain, compounded by the fact that often only T'Small that was a power of 2 was supported. Consider a simple 16 bit heading type, say, typical of what you'd read off a 1553B: Ownship_Heading_Delta : constant := 360.0 / 2 ** 16; type Ownship_Heading is delta Ownship_Heading_Delta range 0.0 .. 360.0; for Ownship_Heading'Small use Ownship_Heading_Delta; How many Ada 83 or Ada 95 compilers support this declaration? My bet is few (if any), despite the fact that this declaration isn't unreasonable, since it is typical of the needs of applications in the domain for which Ada was designed. What motivates the use of floating point is that the fixed point declaration above doesn't compile. So here's what an Ada programmer does: We'll declare a fixed point type with a small that's a power of 2: Fixed_16_U_16_Delta : constant := 1.0 / 2 ** 16; type Fixed_16_U_16 is delta Fixed_16_U_16_Delta range 0.0 .. 1.0; for Fixed_16_U_16'Small use Fixed_16_U_16_Delta; We'll declare a floating point type with the range we require. Since there are 16 bits of precision, we need a floating point type with ceiling (16 / 3.32) = 5 digits of precision. type Ownship_Heading is digits 5 range 0.0 .. 360.0; So he reads the data off the interface using a fixed point type, and converts it to a floating point type: declare Normalized_Heading : Fixed_16_U_16; Heading : Ownship_Heading; begin Read (fd, Normalized_Heading); Heading := 360.0 * Ownship_Heading (Normalized_Heading); end; Now I'm back to square one: how do I compare values of ownship heading? Yes, people routinely use floating point types - probably inappropriately - but fixed point type support has traditionally been weak. Perhaps this will change in Ada 95. I'm not unsympathetic to your view that putting advice about floating point types in the AQ&S may very well create more problems then it solves, but there needs to be some published guidelines about how to use Ada's real types to solve typical problems, such as reading a real number from an external device. -------------------------------------------------------------------- Matthew Heaney Software Development Consultant (818) 985-1271