<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Converting from Int to float in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Converting-from-Int-to-float/m-p/210492#M8269</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a strange behaviour in my project. I would like to receive a 32bit value via CAN and interprete it as a float value.&lt;/P&gt;&lt;P&gt;But the conversion to float seems to be wrong.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example when I try to do the following:&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;int32_t fixTest = 0x3fc00000; //should be 1.5&lt;/P&gt;&lt;P&gt;float testValue = (float)fixTest;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my case test Value is 1.06956e9 instead of the right value 1.5;&lt;/P&gt;&lt;P&gt;What am I missing here? Is something wrong with my project settings?&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using Codewarrior 10.3 and MPC5643L (Leopard).&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 17 Dec 2012 11:50:37 GMT</pubDate>
    <dc:creator>anze</dc:creator>
    <dc:date>2012-12-17T11:50:37Z</dc:date>
    <item>
      <title>Converting from Int to float</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Converting-from-Int-to-float/m-p/210492#M8269</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a strange behaviour in my project. I would like to receive a 32bit value via CAN and interprete it as a float value.&lt;/P&gt;&lt;P&gt;But the conversion to float seems to be wrong.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example when I try to do the following:&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;int32_t fixTest = 0x3fc00000; //should be 1.5&lt;/P&gt;&lt;P&gt;float testValue = (float)fixTest;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my case test Value is 1.06956e9 instead of the right value 1.5;&lt;/P&gt;&lt;P&gt;What am I missing here? Is something wrong with my project settings?&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using Codewarrior 10.3 and MPC5643L (Leopard).&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Dec 2012 11:50:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Converting-from-Int-to-float/m-p/210492#M8269</guid>
      <dc:creator>anze</dc:creator>
      <dc:date>2012-12-17T11:50:37Z</dc:date>
    </item>
    <item>
      <title>Re: Converting from Int to float</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Converting-from-Int-to-float/m-p/210493#M8270</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You get what is specified in subject, big integer is converted to float correctly. But I see you want to treat integer as a binary representation of float. Try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;float testValue;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; *(int32_t*)&amp;amp;testValue = fixTest;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;typedef union{int32_t i, float f} intfloat;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;intfloat tv;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; tv.i = fixTest;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; testValue = tv.f;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 05 Jan 2013 06:57:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Converting-from-Int-to-float/m-p/210493#M8270</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2013-01-05T06:57:36Z</dc:date>
    </item>
  </channel>
</rss>

