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,T_ANY_PILL_PRICE 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-15 21:39:17 PST Date: Sat, 16 Aug 2003 12:21:47 +0800 From: Adrian Hoe User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021204 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: float with 24-bit resolution References: <3F3CCB0F.543478AF@adrianhoe.nospam.com.my> In-Reply-To: X-Enigmail-Version: 0.71.0.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 219.95.187.227 X-Original-NNTP-Posting-Host: 219.95.187.227 Message-ID: <3f3db1a9$1_1@news.tm.net.my> X-Trace: news.tm.net.my 1061007785 219.95.187.227 (16 Aug 2003 12:23:05 +0800) Organization: TMnet Malaysia Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!nntp.abs.net!ash.uu.net!news1.tm.net.my Xref: archiver1.google.com comp.lang.ada:41553 Date: 2003-08-16T12:21:47+08:00 List-Id: Simon Wright wrote: > "Jeffrey Creem" writes: > > >>package My_Pack is >> >>The_Delta : constant := 4.291534424e-5; >> type Probably_Gonna_Work_But_Language_Lawyers_Will_Complain_Type is delta >>The_Delta range - 360.0 .. 359.9999571; > > > You need to use the compiler's inbuilt infinite precision arithmetic here: > > package Angles is > > Angle_Delta : constant := 360.0 / 2 ** 23; > > type Angle is delta Angle_Delta range -360.0 .. 360.0 - Angle_Delta; > for Angle'Small use Angle_Delta; > for Angle'Size use 24; > > end Angles; > > (this compiles, at least!) OK, I just reply to all the responses in one single reply. My first description of the requirement is to read and write position value of azimuth and elevation to an external device and the second description of the requirement describes the data read and written of the velocity of azimuth and elevation. The device has an accuracy of +-0.0014 degrees or +-25urad. These values (position and velocity) will be read from the device and some calculation will take place and new values (position and velocity) will then be sent to the device. After a brief analysis based on the solution by Simon, that solve the mapping problem for a while. This implementation gives the following values: Angle'first => -360.00000 Angle'last => 359.99996 I did a quick and dirty interface and have the maximum position read. My Ada code spills 359.99996 but the device demo software which is written in C spills 359.9999571 which conforms to my first requirement description. I then send a position data with 359.99996 back to the device and have the position read by the device demo software, it reads 359.9999611. I don't understand why 359.9999611 instead of 359.99996? (Scratching head :) How do I have Angle to give me precision of 7 decimal? I don't have the source code for the C library and the C demo software. My quick and dirty interface in Ada like this: ----------------------------------------------------------------------- procedure Dirty is Angle_Delta : constant := 360.0 / 2 ** 23; type Angle is delta Angle_Delta range -360.0 .. 360.0 - Angle_Delta; for Angle'Small use Angle_Delta; for Angle'Size use 24; Position : Angle; begin Position_Read (Position); -- Call an Ada procedure which interface to C library function put_line (Angle'Image (Position)); Position_Write (Position); -- Call an Ada procedure which interface to C library function ------------------------------------------------------------------------- end Dirty;