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: dewar@merv.cs.nyu.edu (Robert Dewar) Subject: Re: floating point comparison Date: 1997/08/03 Message-ID: #1/1 X-Deja-AN: 262135047 References: <33DF6F43.6EEA4806@digicomp.com> <5rqehs$g1r$1@odin.cc.pdx.edu> <33E11967.4A30@nr.net> <33E214C3.311C@pseserv3.fw.hac.com> Organization: New York University Newsgroups: comp.lang.ada Date: 1997-08-03T00:00:00+00:00 List-Id: Matthew said: 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. Robert replies I will say it again, to use floating-point without knowing anything about it makes as much sense as trying to write an Ada program when you know nothing about programming. That goes for all human endeavors, if you want to do something right, you need to know what you are doing. You are giving the impression that you really know *nothing* about fpt, which is fine, but then what makes you think you can possibly learn a complex subject by virtue of a few simple rules. Anyone who understands floating-point will be able to deal with scenarios such as you mention without any special knowledge of Ada. These are fpt problems, not Ada problems! As to your question, how do you compare values of ownship heading? Impossible of course to answer without specs as to the accuracy of the input, and the purpose of the comparison. By the way 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; of course compiles fine in GNAT, what might possibly give you the impression that it would not. GNAT supports arbitrary smalls, with a precision of up to 64 bits. Remember GNAT is a full language compiler, not a subset!