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-Thread: 103376,65b3f028266fd999 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,UTF8 Path: g2news1.google.com!news2.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx01.iad01.newshosting.com!newshosting.com!novia!news-xxxfer.readnews.com!news-out.readnews.com!postnews3.readnews.com!not-for-mail Date: Sun, 15 Aug 2010 21:03:07 -0400 From: "Peter C. Chapin" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.8) Gecko/20100802 Lightning/1.0b2 Thunderbird/3.1.2 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Question about ordinary fixed point types. References: <4c685fac$0$2373$4d3efbfe@news.sover.net> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-ID: <4c688e67$0$2389$4d3efbfe@news.sover.net> Organization: SoVerNet (sover.net) NNTP-Posting-Host: f38fc331.news.sover.net X-Trace: DXC=6` On 2010-08-15 18:08, Yannick Duchêne (Hibou57) wrote: > Hi Peter, nice to see you again, Hi! > What do you mean with “to the next machine number in the type” ? That > this may not advance in some case ? The manual talks about machine numbers which, as I understand it, are the mathematical values which are precisely represented by the fixed point type. In my case they are the multiples of 2**(-11). In my first (less informed?) attempt I used Angle_Type'Delta like this: Angle := Angle + Angle_Type'Delta; However, the distance between the represented values (the "machine numbers") is not Delta, but rather Small. I suppose it wouldn't matter much because the resulting value would "snap to" a machine number when assigned to Angle. Well, I think. > If the matter is the precise exploration of a precise set of points in a > range, I may have a silly suggestion (silly in some sense, while not so > much in some others) : why not use an array of predefined points ? Here, > you would have an array of 12566 points. Ok, this may seems a big array, > some design for hight efficiency. I need to do real number computations on a microcontroller without a floating point unit. I believe the various numeric quantities that I need can be normalized into fairly narrow ranges so it seemed to me that this is a perfect application of fixed point types. The compiler stores the numbers as integers representing the appropriate multiple of Small. I'm not using GNAT on the microcontroller but if the Ada compiler I am using does the same thing as GNAT it will be able to fit Angle_Type as it is currently defined into a 16 bit word and compute with it using integer instructions. In my environment that is essential. At the moment I'm looking at implementing some basic trig functions such as Sine and Cosine taking Angle_Type parameters. My test program compares the computed results against the much higher precision values from GNAT's normal numeric library. I can thus assess the overall accuracy of my implementation. I want to check every possible Angle_Type value to be sure there are no surprises. For example right now I get Constraint_Error when I attempt to compute the Sine of Angle_Type'First. This is apparently because Angle_Type'First is actually slightly less than -Pi and my simplistic implementation can't cope with that. Peter BTW, I will probably need a smaller delta than 0.0005 eventually (I think). But I imagine changing that will be easy enough once I understand what I'm doing. Alas, using too small a delta will probably force the compiler to use 32 bits to store an Angle_Type value and that's an undesirable thing on my machine.