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,FREEMAIL_FROM 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 Path: g2news1.google.com!news2.google.com!postnews.google.com!s9g2000yqd.googlegroups.com!not-for-mail From: sjw Newsgroups: comp.lang.ada Subject: Re: Question about ordinary fixed point types. Date: Tue, 17 Aug 2010 07:37:21 -0700 (PDT) Organization: http://groups.google.com Message-ID: <41f79b9c-b970-4c19-8701-688cb2b8fe12@s9g2000yqd.googlegroups.com> References: <4c685fac$0$2373$4d3efbfe@news.sover.net> <4c688e67$0$2389$4d3efbfe@news.sover.net> NNTP-Posting-Host: 20.133.0.13 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1282055841 19242 127.0.0.1 (17 Aug 2010 14:37:21 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 17 Aug 2010 14:37:21 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: s9g2000yqd.googlegroups.com; posting-host=20.133.0.13; posting-account=_RXWmAoAAADQS3ojtLFDmTNJCT0N2R4U User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8,gzip(gfe) Xref: g2news1.google.com comp.lang.ada:13457 Date: 2010-08-17T07:37:21-07:00 List-Id: On Aug 16, 10:23=A0am, Simon Wright wrote: > "Peter C. Chapin" writes: > > > 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 tha= t > > 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. > > It would be very normal in that sort of environment to work in binary > fractions of 180 degrees. > > with Ada.Numerics; > with Ada.Text_IO; use Ada.Text_IO; > procedure Angles is > =A0 =A0Angle_Type_Delta : constant :=3D Ada.Numerics.Pi * 2.0 ** (-16); > =A0 =A0type Angle_Type is > =A0 =A0 =A0delta Angle_Type_Delta > =A0 =A0 =A0 =A0range -Ada.Numerics.Pi / 2 .. Ada.Numerics.Pi / 2; Eep. Angle_Type_Delta : constant :=3D Ada.Numerics.Pi * 2.0 ** (-15); type Angle_Type is delta Angle_Type_Delta range -Ada.Numerics.Pi .. Ada.Numerics.Pi; > =A0 =A0for Angle_Type'Small use Angle_Type_Delta; > =A0 =A0for Angle_Type'Size use 16;