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!news4.google.com!proxad.net!feeder1-2.proxad.net!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Question about ordinary fixed point types. Date: Mon, 16 Aug 2010 10:23:56 +0100 Organization: A noiseless patient Spider Message-ID: References: <4c685fac$0$2373$4d3efbfe@news.sover.net> <4c688e67$0$2389$4d3efbfe@news.sover.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Mon, 16 Aug 2010 09:23:57 +0000 (UTC) Injection-Info: mx01.eternal-september.org; posting-host="KCXegvZb5vh43D+f3BR6Ew"; logging-data="27260"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/TlcApI0tc4rFKUlDvJcD3OazvQQ6l2Dc=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (darwin) Cancel-Lock: sha1:6GfWuJP+buz0vE7T5ew+29LJBHk= sha1:qYqg8IaGXyNfIjRd/WsLYz64PYc= Xref: g2news1.google.com comp.lang.ada:13394 Date: 2010-08-16T10:23:56+01:00 List-Id: "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 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. 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 Angle_Type_Delta : constant := Ada.Numerics.Pi * 2.0 ** (-16); type Angle_Type is delta Angle_Type_Delta range -Ada.Numerics.Pi / 2 .. Ada.Numerics.Pi / 2; for Angle_Type'Small use Angle_Type_Delta; for Angle_Type'Size use 16; Count_Of_Values : Positive; Value : Angle_Type; begin Put_Line ("angle_type'first: " & Long_Float'Image (Long_Float (Angle_Type'First))); Put_Line ("angle_type'last: " & Long_Float'Image (Long_Float (Angle_Type'Last))); Value := Angle_Type'First; Count_Of_Values := 1; loop exit when Value = Angle_Type'Last; Count_Of_Values := Count_Of_Values + 1; Value := Value + Angle_Type'Small; end loop; Put_Line ("count_of_values: " & Positive'Image (Count_Of_Values)); end Angles; $ ./angles angle_type'first: -1.57079632679490E+00 angle_type'last: 1.57074838989528E+00 count_of_values: 65536