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=0.5 required=5.0 tests=BAYES_05,FREEMAIL_FROM, HK_RANDOM_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e7b0825eca61cc23 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!g44g2000cwa.googlegroups.com!not-for-mail From: "stuart clark" Newsgroups: comp.lang.ada Subject: Re: floating point to fixed point conversion Date: 22 Feb 2006 03:01:08 -0800 Organization: http://groups.google.com Message-ID: <1140606068.242508.155830@g44g2000cwa.googlegroups.com> References: <1140560157.376760.292570@g43g2000cwa.googlegroups.com> NNTP-Posting-Host: 202.6.152.183 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1140606073 23377 127.0.0.1 (22 Feb 2006 11:01:13 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 22 Feb 2006 11:01:13 +0000 (UTC) In-Reply-To: <1140560157.376760.292570@g43g2000cwa.googlegroups.com> User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: g44g2000cwa.googlegroups.com; posting-host=202.6.152.183; posting-account=wseb7A0AAACoGSN9Y-Rms_un18idFn-Q Xref: g2news1.google.com comp.lang.ada:3068 Date: 2006-02-22T03:01:08-08:00 List-Id: Not sure if this is what you are after but an example from a real IDD, where floats are represented as 16 bit signed integers, the 16th bit is the sign bit. Eg from a real life navigational computer IDD magnetic heading = +/-180 degrees. bits to use = 15, the 16th bit the sign bit pass integers across an interface, which are then converted to floats using a known scaling factor. scaling factor = 180 / (2^15 ) = 0.005493.... we define the integer value of 1 = 0.005493.... and we call this value the LSB. >>From basics where 15 bits can represent a max value of 2^15 -1 we now have max value of 180 - LSB (iw 2^15 =180 and 1 =LSB) therefore to send 180 - LSB across an interface what integer value do you need = 180 / scaling factor = (180 - 0.005493..) / 0.005493 = 32767 (the old 2^15-1) = 0x7FFF 90 degrees = 90 / 0.005493 = 16383.5 = 0x3FFF but note there is an accuracy loss as 0x3FFF * 0.005493 = 89.997 Thats hows its done in real life, hope it helps! Stuart Clark