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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7a2d45f282a1da1c X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-08-16 08:22:32 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread3.news.pas.earthlink.net.POSTED!not-for-mail From: "Matthew Heaney" Newsgroups: comp.lang.ada References: <3F3CCB0F.543478AF@adrianhoe.nospam.com.my> Subject: Re: float with 24-bit resolution X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: Date: Sat, 16 Aug 2003 15:22:32 GMT NNTP-Posting-Host: 65.110.133.134 X-Complaints-To: abuse@earthlink.net X-Trace: newsread3.news.pas.earthlink.net 1061047352 65.110.133.134 (Sat, 16 Aug 2003 08:22:32 PDT) NNTP-Posting-Date: Sat, 16 Aug 2003 08:22:32 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:41584 Date: 2003-08-16T15:22:32+00:00 List-Id: wrote in message news:3F3CCB0F.543478AF@adrianhoe.nospam.com.my... > Hi, > > I looked through the LRM and searched CLA but I could not find any > solution. Perhaps I've overlook somewhere. > > I need a float with 24-bit resolution. My data needs to be encoded into > 24 bits at a scaling of 720 degrees / 2^24 bits with the most > significant bit being the sign bit. This results in a value that ranges > from +359.9999571 degrees (0x7FFFFF) to -360.0000000 degrees (0x800000) > at increments of approximately 4.291534424e-5 degrees per bit. You're not asking for a floating point type at all -- you're asking for a fixed point type. This type has the properties you specified: Degrees_Type_Delta : constant := 360.0 / 2**23; type Degrees_Type is delta Degrees_Type_Delta range -360.0 .. 360.0; for Degrees_Type'Small use Degrees_Type_Delta; for Degrees_Type'Size use 24; Here is a test program, that dumps the bits of various values of Degrees_Type: with Ada.Text_IO; use Ada.Text_IO; with Ada.Unchecked_Conversion; procedure Test_Fixed is Degrees_Type_Delta : constant := 360.0 / 2**23; type Degrees_Type is delta Degrees_Type_Delta range -360.0 .. 360.0; for Degrees_Type'Small use Degrees_Type_Delta; for Degrees_Type'Size use 24; type I24_Type is range -2**23 .. 2**23 - 1; for I24_Type'Size use 24; function To_I24 is new Ada.Unchecked_Conversion (Degrees_Type, I24_Type); package I24_IO is new Ada.Text_IO.Integer_IO (I24_Type); use I24_IO; package Degrees_IO is new Ada.Text_IO.Fixed_IO (Degrees_Type); use Degrees_IO; F : Degrees_Type; I : I24_Type; begin F := 45.0; I := To_I24 (F); Put (F); Put (' '); Put (I, Base => 16); New_Line; F := 90.0; I := To_I24 (F); Put (F); Put (' '); Put (I, Base => 16); New_Line; F := 135.0; I := To_I24 (F); Put (F); Put (' '); Put (I, Base => 16); New_Line; F := 180.0; I := To_I24 (F); Put (F); Put (' '); Put (I, Base => 16); New_Line; F := 225.0; I := To_I24 (F); Put (F); Put (' '); Put (I, Base => 16); New_Line; F := 270.0; I := To_I24 (F); Put (F); Put (' '); Put (I, Base => 16); New_Line; F := Degrees_Type'Last; I := To_I24 (F); Put (F); Put (' '); Put (I, Base => 16); New_Line; --negative values: F := -45.0; I := To_I24 (F); Put (F); Put (' '); Put (I, Base => 16); New_Line; F := -90.0; I := To_I24 (F); Put (F); Put (' '); Put (I, Base => 16); New_Line; F := -135.0; I := To_I24 (F); Put (F); Put (' '); Put (I, Base => 16); New_Line; F := -180.0; I := To_I24 (F); Put (F); Put (' '); Put (I, Base => 16); New_Line; F := -225.0; I := To_I24 (F); Put (F); Put (' '); Put (I, Base => 16); New_Line; F := -270.0; I := To_I24 (F); Put (F); Put (' '); Put (I, Base => 16); New_Line; F := Degrees_Type'First; I := To_I24 (F); Put (F); Put (' '); Put (I, Base => 16); New_Line; end Test_Fixed;