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 08:01:44 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!peernews-us.colt.net!newsfeed.news2me.com!elnk-nf2-pas!newsfeed.earthlink.net!wn14feed!wn13feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!rwcrnsc54.POSTED!not-for-mail From: "Jeffrey Creem" Newsgroups: comp.lang.ada References: <3F3CCB0F.543478AF@adrianhoe.nospam.com.my> <3f3cd7f4$1_2@news.tm.net.my> <3f3cd84f$1_2@news.tm.net.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: NNTP-Posting-Host: 66.31.5.146 X-Complaints-To: abuse@comcast.net X-Trace: rwcrnsc54 1060959702 66.31.5.146 (Fri, 15 Aug 2003 15:01:42 GMT) NNTP-Posting-Date: Fri, 15 Aug 2003 15:01:42 GMT Organization: Comcast Online Date: Fri, 15 Aug 2003 15:01:42 GMT Xref: archiver1.google.com comp.lang.ada:41522 Date: 2003-08-15T15:01:42+00:00 List-Id: "Adrian Hoe" wrote in message news:3f3cd84f$1_2@news.tm.net.my... > > Yes, I am trying to talk to some hardware. > Ok.... Certainly the fixed point definition I provided approaches a solution. Complications that you need to think about and or ignore/document, handle are: 1) Byte Order - The little endian/big endian thing. 24 bit types on little endian machines talking to big edian H/W (or vice versa).. 2) Getting the 24 bit type in the first place. How do you get the data from the HW into memory to work with to start with. It is not uncommon to have to do 32 bit or 16 bit transfers so you need a method for getting the data to start with. 3) As another poster mentioned, there is the issue of what you do with the data once you get it. These fixed point types might be good as a starting point to get the data into a format that you can begin to work with but once you start doing calculations on them you will almost certainly need additional higher resolution fixed point types or floating point of some precision to do you caculations. There are more....This is not all that complicated but you do need to think about this before you start coding. Also, it may be CRITICAL (depending on what this is used for :) to understand why we keep harping on the fact that fixed point types are not floating point types and to understand the limitations of each. The basic difference is somewhat highlighted by the way one goes about starting to declare each of these types in Ada (although the differences themselves really have nothing at all to do with Ada per se) as a first order approximation of the difference, realize that (usually) fixed point types are implemented using the integer math operations of the processor while floating point is (usually) implemented using the floating point unit. Fixed point numbers always have the same precision (essentially) for all values that they hold while floating point numbers have a precision that varies (floats!) depending on the size of the number involved. It is best to visualize the underlying representation of these two types (a working model for your mind, which may not be exactly (ok..certainly is not the same as) how the compiler implements it) as Fixed point An Integer (which can vary) and a non-changing LSB that is always the same. To figure out what value the fixed point number represents at any given time, multiply (in your mind) the Integer times the LSB and that is the value that the number holds. Floating Point This can thought of as the computer storing part of the number in a fixed length string and a separate exponent as a smaller integer The_Digits : '.' & String(1 .. 6); -- (Ok total pseudo code here, basically saying that there is a decimal point followed by some numeric characters) The_Exponent : Integer range -31 .. 31 (or something like that) So, one way to store the number 122.1 would be to have "The_Digits" equal to .1221000 and The_Exponent = +3 So, as you can see, the float can hold really big or really small numbers but as they get really big you eventually can not even represent digits to the right of the actual decimal point. In reality (especially for floats) the actual representation and limitations are much different and even more complicated but one thing you can quickly see even with this working "model" is that one could easily end up with floats where A + B = A Even when B was non-zero if the exponent of A is enough higher than B.