Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.arch.embedded > #23527
| Path | csiph.com!feeder.erje.net!2.us.feeder.erje.net!bloom-beacon.mit.edu!bloom-beacon.mit.edu!panix!not-for-mail |
|---|---|
| From | Grant Edwards <invalid@invalid.invalid> |
| Newsgroups | comp.arch.embedded |
| Subject | Re: Integer/Fixedpoint to 32 bit float |
| Date | Wed, 6 Apr 2016 14:40:49 +0000 (UTC) |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Lines | 54 |
| Message-ID | <ne375g$huo$2@reader1.panix.com> (permalink) |
| References | <ne3289$f5a$1@gioia.aioe.org> <ne35hv$kaq$1@dont-email.me> |
| NNTP-Posting-Host | 67-130-15-94.dia.static.qwest.net |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| X-Trace | reader1.panix.com 1459953649 18392 67.130.15.94 (6 Apr 2016 14:40:49 GMT) |
| X-Complaints-To | abuse@panix.com |
| NNTP-Posting-Date | Wed, 6 Apr 2016 14:40:49 +0000 (UTC) |
| User-Agent | slrn/1.0.2 (Linux) |
| Xref | csiph.com comp.arch.embedded:23527 |
Show key headers only | View raw
On 2016-04-06, Dimiter_Popoff <dp@tgi-sci.com> wrote:
> On 06.4.2016 г. 16:17, Vincent vB wrote:
>> Currently I'm in the process of replacing a custom compass /
>> accelerometer with an ST LSM303D. The 'old' custom device produced
>> single precision floats. Without parsing the values there where just
>> passed inside a UDP packet.
>>
>> Unfortunately the LSM303D produces 16 bit signed integers. So, the
>> embedded system needs to convert these values to floats. The scaling it
>> self is quite simple: Values -32768..32767 need to be scaled to [-2,2).
>>
>> Now, my hardware has no floating point support. However doing the
>> following:
>>
>> float output = ( (float)input ) / 16384f;
>>
>> will require quite a bit of FP magic. I would imagine that this:
>>
>> const float scale = 1f / 16384f;
>> float output = ( (float)input ) * scale;
>>
>> may be faster, but still requires FP multiply support.
>>
>> Is there a simple and fast way which I can use to convert these integers
>> to floats without the aid of an FP library? I have not found much code
>> in this respect.
>>
>> Vincent
>
> Of course there is, will cost a few operations. You can look up the
> IEEE 32 bit floating point format and figure out how to do it.
> Basically it will take several shifts left (you will have to count
> these) of your 16 bit integer until its MSB gets positioned as bit
> 23, subtract the count of shifts it took to get there from 150 ($96) and
> insert this result into bits 23 to 32 (this will overwrite the
> MSB which got to position 23).
> For negative input numbers, negate first, convert as above and
> set bit 31 of the final result to 1.
[Remember to check for a negative input value, convert it to positive,
and then later set the sign bit in the FP result]
That converts the value to FP.
To scale it by factor of 2/32768 you should be able to simply subtract
14 from the exponent.
Don't forget that the exponent is stored in an excess-127
representation (not 2's compliment or sign-magnitude).
--
Grant Edwards grant.b.edwards Yow! I guess it was all a
at DREAM ... or an episode of
gmail.com HAWAII FIVE-O ...
Back to comp.arch.embedded | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Integer/Fixedpoint to 32 bit float Vincent vB <embedded@spam.com> - 2016-04-06 15:17 +0200
Re: Integer/Fixedpoint to 32 bit float Dimiter_Popoff <dp@tgi-sci.com> - 2016-04-06 17:16 +0300
Re: Integer/Fixedpoint to 32 bit float Dimiter_Popoff <dp@tgi-sci.com> - 2016-04-06 17:21 +0300
Re: Integer/Fixedpoint to 32 bit float Grant Edwards <invalid@invalid.invalid> - 2016-04-06 14:40 +0000
Re: Integer/Fixedpoint to 32 bit float Dave Nadler <drn@nadler.com> - 2016-04-06 08:21 -0700
Re: Integer/Fixedpoint to 32 bit float Robert Wessel <robertwessel2@yahoo.com> - 2016-04-06 12:33 -0500
Re: Integer/Fixedpoint to 32 bit float Robert Wessel <robertwessel2@yahoo.com> - 2016-04-06 12:36 -0500
Re: Integer/Fixedpoint to 32 bit float Grant Edwards <invalid@invalid.invalid> - 2016-04-06 17:56 +0000
Re: Integer/Fixedpoint to 32 bit float Dimiter_Popoff <dp@tgi-sci.com> - 2016-04-06 22:45 +0300
Re: Integer/Fixedpoint to 32 bit float Vincent vB <embedded@spam.com> - 2016-04-07 09:06 +0200
Re: Integer/Fixedpoint to 32 bit float Vincent vB <embedded@spam.com> - 2016-04-07 11:26 +0200
Re: Integer/Fixedpoint to 32 bit float Vincent vB <embedded@spam.com> - 2016-04-07 11:29 +0200
Re: Integer/Fixedpoint to 32 bit float Wouter van Ooijen <wouter@voti.nl> - 2016-04-06 18:00 +0200
Re: Integer/Fixedpoint to 32 bit float Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2016-04-06 21:35 +0300
Re: Integer/Fixedpoint to 32 bit float Grant Edwards <invalid@invalid.invalid> - 2016-04-06 18:47 +0000
Re: Integer/Fixedpoint to 32 bit float Vincent vB <embedded@spam.com> - 2016-04-07 08:52 +0200
Re: Integer/Fixedpoint to 32 bit float Tim Wescott <seemywebsite@myfooter.really> - 2016-04-06 16:05 -0500
Re: Integer/Fixedpoint to 32 bit float Dimiter_Popoff <dp@tgi-sci.com> - 2016-04-07 00:23 +0300
Re: Integer/Fixedpoint to 32 bit float Rob Gaddi <rgaddi@highlandtechnology.invalid> - 2016-04-06 21:30 +0000
Re: Integer/Fixedpoint to 32 bit float Clifford Heath <no.spam@please.net> - 2016-04-07 09:23 +1000
Re: Integer/Fixedpoint to 32 bit float Vincent vB <embedded@spam.com> - 2016-04-07 09:07 +0200
Re: Integer/Fixedpoint to 32 bit float Tim Wescott <tim@seemywebsite.com> - 2016-04-07 11:14 -0500
Re: Integer/Fixedpoint to 32 bit float Tim Wescott <seemywebsite@myfooter.really> - 2016-04-06 18:36 -0500
Re: Integer/Fixedpoint to 32 bit float lasselangwadtchristensen@gmail.com - 2016-04-06 17:03 -0700
Re: Integer/Fixedpoint to 32 bit float Vincent vB <embedded@spam.com> - 2016-04-07 09:04 +0200
Re: Integer/Fixedpoint to 32 bit float David Brown <david.brown@hesbynett.no> - 2016-04-07 10:21 +0200
Re: Integer/Fixedpoint to 32 bit float Dimiter_Popoff <dp@tgi-sci.com> - 2016-04-07 11:28 +0300
Re: Integer/Fixedpoint to 32 bit float David Brown <david.brown@hesbynett.no> - 2016-04-07 10:41 +0200
Re: Integer/Fixedpoint to 32 bit float Dimiter_Popoff <dp@tgi-sci.com> - 2016-04-07 11:47 +0300
Re: Integer/Fixedpoint to 32 bit float David Brown <david.brown@hesbynett.no> - 2016-04-07 11:40 +0200
Re: Integer/Fixedpoint to 32 bit float Vincent vB <embedded@spam.com> - 2016-04-07 12:50 +0200
Re: Integer/Fixedpoint to 32 bit float David Brown <david.brown@hesbynett.no> - 2016-04-07 13:52 +0200
Re: Integer/Fixedpoint to 32 bit float Dimiter_Popoff <dp@tgi-sci.com> - 2016-04-07 22:14 +0300
Re: Integer/Fixedpoint to 32 bit float Nobody <nobody@nowhere.invalid> - 2016-04-08 03:39 +0100
csiph-web