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,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder.news-service.com!tudelft.nl!txtfeed1.tudelft.nl!zen.net.uk!dedekind.zen.co.uk!news.netfront.net!not-for-mail From: Jeffrey Carter Newsgroups: comp.lang.ada Subject: Re: Question about ordinary fixed point types. Date: Sun, 15 Aug 2010 21:11:03 -0700 Organization: Netfront http://www.netfront.net/ Message-ID: References: <4c685fac$0$2373$4d3efbfe@news.sover.net> <4c688e67$0$2389$4d3efbfe@news.sover.net> NNTP-Posting-Host: 75.211.52.183 Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: adenine.netfront.net 1281931866 79803 75.211.52.183 (16 Aug 2010 04:11:06 GMT) X-Complaints-To: news@netfront.net NNTP-Posting-Date: Mon, 16 Aug 2010 04:11:06 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.11) Gecko/20100713 Thunderbird/3.0.6 In-Reply-To: <4c688e67$0$2389$4d3efbfe@news.sover.net> Xref: g2news1.google.com comp.lang.ada:13379 Date: 2010-08-15T21:11:03-07:00 List-Id: On 08/15/2010 06:03 PM, Peter C. Chapin wrote: > > 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. Consider this example, which I 1st encountered in 1984: with Ada.Text_IO; procedure Fixed_Test is type Money is delta 0.01 range -100.0 .. 100.0; Cent : constant Money := Money'Delta; Change : Money := 0.0; begin -- Fixed_Test Sum : for I in 1 .. 5 loop Change := Change + Cent; end loop Sum; Ada.Text_IO.Put_Line (Item => Money'Image (Change) ); end Fixed_Test; Typically, the 'Small will be 2#0.000_000_1#, and the program will output 0.04. The program adds the machine number closest to 'Delta (which is 'Small) each time, not 'Delta, so there's no "snapping" taking place, except in the conversion of 0.01 to a machine number of type Money. > 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. That is a reason for the existence of fixed-point types. > 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. You can always say for Angle_Value'Size use 16; -- Jeff Carter "Son of a window-dresser." Monty Python & the Holy Grail 12 --- news://freenews.netfront.net/ - complaints: news@netfront.net ---