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-15 06:39:36 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!cambridge1-snf1.gtei.net!news.gtei.net!bos-service1.ext.raytheon.com!dfw-service2.ext.raytheon.com.POSTED!not-for-mail Message-ID: <3F3CE28D.B841A191@raytheon.com> From: Mark Johnson X-Mailer: Mozilla 4.76 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: float with 24-bit resolution References: <3F3CCB0F.543478AF@adrianhoe.nospam.com.my> <3f3cd7f4$1_2@news.tm.net.my> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Fri, 15 Aug 2003 08:39:25 -0500 NNTP-Posting-Host: 192.27.48.39 X-Complaints-To: news@ext.ray.com X-Trace: dfw-service2.ext.raytheon.com 1060954775 192.27.48.39 (Fri, 15 Aug 2003 08:39:35 CDT) NNTP-Posting-Date: Fri, 15 Aug 2003 08:39:35 CDT Organization: Raytheon Company Xref: archiver1.google.com comp.lang.ada:41511 Date: 2003-08-15T08:39:25-05:00 List-Id: Adrian Hoe wrote: > > Jeffrey Creem wrote: > > wrote in message > > news:3F3CCB0F.543478AF@adrianhoe.nospam.com.my... > > > >>Hi, > >> [snip request for 24 bit +/- 360 degree values] > > This does not sound anything like a float at all. It sounds much more like a > > typical implementation of a fixed point type. Something along the lines of > > Let me second this comment - what you are asking for appears to be a "fixed point" type and not a float. You may find it easier to search for this kind of example when using "fixed point" instead of "float". > > [snip - nice language lawyer type declaration] > > What are you really trying to achieve at a higher level (e.g. talking to > > some hardware, sending some message to a device, etc?) > > We can certainly give you better answers with this kind of information. > Consider I have another data type which is to be encoded into 24 bits at > a scaling of 3600 degrees/sec / 2^24 bits with the most significant bit > being the sign bit. This results in a value that ranges from > +1799.999785 degrees per second (0x7FFFFF) to -1800.000 degrees per > second (0x800000) at increments of approximately 2.14576721e-4 degrees > per second per bit. > Ah. It appears you want to do some integration of speeds to get position. > Can I declare just one 24-bit resolution float with a 24 bit storage > size for both problems? How? > No. First, as mentioned before, please refer to this as "fixed point". Second, they are different data types. They happen to have a similar underlying bit pattern but will be represented to the user in different forms. Third, let's say they are the same type - then you could say X := speed + distance; to get some garbage value for X, when you really want something like new_distance := speed * delta_time + distance; to get an updated distance. This would require: - three types (speed, distance, time) - arithmetic operators for "*"(speed, time) and similar operations and some patience on your part. A quick review of "Dimensional Analysis" may help as well. Fourth, when dealing with fixed point arithmetic, it is often helpful to consider factors such as - for intermediate calculations, having a double (or in your case - perhaps just 32 bit) precision data type can help simplify arithmetic. - when you multiply two numbers together, you get a double precision result. Which part will you keep, the most or least significant portion? It depends on your application which is more important. - when you divide two numbers (dp/sp) - you get a result and remainder. If you want rounding, you must handle it yourself. - when you add two numbers, they must be "aligned" and of the same type. You can certainly add two 24 bit values together (to get a 24 or 25 bit result) but if the bits are not aligned properly, you get a mess. Using the two data types (speed, distance), the LSB is about 5x different between them. You have to scale one or the other value before you add to get a meaningful value. Which one you scale has an effect on the result. For example, on one system I simulated, a ship did not move until reaching 5 knots because the result of (speed * delta_time) was less than the LSB of the distance value. We had to use double precision for location (X, Y) for most calculations and then use the MSB portion for display on the screen. Now - having said all of that, are you still interested in fixed point arithmetic, and if so what is the real problem being solved so we can suggest a complete answer? --Mark