From: "Matthew Heaney" <matthewjheaney@earthlink.net>
Subject: Re: float with 24-bit resolution
Date: Sat, 16 Aug 2003 15:22:32 GMT
Date: 2003-08-16T15:22:32+00:00 [thread overview]
Message-ID: <Y_r%a.5294$7z1.2102@newsread3.news.pas.earthlink.net> (raw)
In-Reply-To: 3F3CCB0F.543478AF@adrianhoe.nospam.com.my
<mailbox@adrianhoe.nospam.com.my> 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;
next prev parent reply other threads:[~2003-08-16 15:22 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-08-15 11:59 float with 24-bit resolution mailbox
2003-08-15 12:24 ` Jeffrey Creem
2003-08-15 12:52 ` Adrian Hoe
2003-08-15 12:54 ` Adrian Hoe
2003-08-15 15:01 ` Jeffrey Creem
2003-08-16 15:29 ` Matthew Heaney
2003-08-15 13:39 ` Mark Johnson
2003-08-15 16:56 ` Robert I. Eachus
2003-08-15 18:08 ` Mark Johnson
2003-08-16 3:30 ` Robert I. Eachus
2003-08-18 13:39 ` Mark Johnson
2003-08-20 21:12 ` Robert I. Eachus
2003-08-21 13:38 ` Mark Johnson
2003-08-16 15:32 ` Matthew Heaney
2003-08-16 15:26 ` Matthew Heaney
2003-08-15 19:56 ` Simon Wright
2003-08-16 4:21 ` Adrian Hoe
2003-08-16 12:59 ` Jeffrey Creem
2003-08-16 15:35 ` Matthew Heaney
2003-08-17 11:40 ` Simon Wright
2003-08-17 13:46 ` Matthew Heaney
2003-08-18 5:05 ` Adrian Hoe
2003-08-18 13:14 ` Matthew Heaney
2003-08-19 3:09 ` Adrian Hoe
2003-08-19 13:00 ` Matthew Heaney
2003-08-30 5:02 ` Randy Brukardt
2003-09-02 16:05 ` Adrian Hoe
2003-09-03 3:31 ` Matthew Heaney
2003-09-03 20:46 ` Simon Wright
2003-09-04 1:43 ` Randy Brukardt
2003-09-04 9:53 ` Jean-Pierre Rosen
2003-09-05 3:46 ` Randy Brukardt
2003-09-05 17:16 ` Warren W. Gay VE3WWG
2003-09-05 19:37 ` Randy Brukardt
2003-09-06 20:48 ` Warren W. Gay VE3WWG
2003-09-08 7:53 ` Dmitry A. Kazakov
2003-09-04 1:45 ` Randy Brukardt
2003-08-16 3:42 ` Robert I. Eachus
2003-08-16 15:38 ` Matthew Heaney
2003-08-16 16:36 ` Robert I. Eachus
2003-08-16 15:22 ` Matthew Heaney [this message]
2003-08-17 11:46 ` Simon Wright
2003-08-18 10:04 ` Martin Dowie
2003-08-20 19:53 ` Robert I. Eachus
2003-08-20 23:36 ` Ludovic Brenta
2003-08-21 13:54 ` Mark Johnson
2003-08-21 14:35 ` Ludovic Brenta
2003-08-22 14:07 ` Mark Johnson
2003-08-22 15:12 ` Jean-Pierre Rosen
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox