<?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>8-bit MicrocontrollersのトピックRe: converting 32-bit Q1.31 type to double</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/converting-32-bit-Q1-31-type-to-double/m-p/899334#M22856</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your reply!&lt;/P&gt;&lt;P&gt;But can we do a direct type casting like&lt;/P&gt;&lt;P&gt;tFrac32 y;&lt;/P&gt;&lt;P&gt;double x ;&lt;/P&gt;&lt;P&gt;x = (double)( y);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 03 May 2019 07:18:44 GMT</pubDate>
    <dc:creator>fixed-term_apar</dc:creator>
    <dc:date>2019-05-03T07:18:44Z</dc:date>
    <item>
      <title>converting 32-bit Q1.31 type to double</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/converting-32-bit-Q1-31-type-to-double/m-p/899332#M22854</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is there any possible way to convert 32-bit Q1.31 type (tFrac32) variable to a double variable in C language?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 May 2019 12:24:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/converting-32-bit-Q1-31-type-to-double/m-p/899332#M22854</guid>
      <dc:creator>fixed-term_apar</dc:creator>
      <dc:date>2019-05-02T12:24:48Z</dc:date>
    </item>
    <item>
      <title>Re: converting 32-bit Q1.31 type to double</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/converting-32-bit-Q1-31-type-to-double/m-p/899333#M22855</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sure. Fraction type is real value times power of two (31 in your case), then convert result from FP to integer. So to convert it back you need to convert your fraction back to float and divide by power of two. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;float f = (float)frac / 2147483648.0;&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;float f = (float)frac * 0.4656612873077392578125E-9; // use multiply by reciprocal of 2^31&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or even more faster using&amp;nbsp;ldexp() function from math.h&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;float f = ldexp(frac, -31);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ldexp multiplies first argument by 2^N, where N is second&amp;nbsp;ldexp argument. ldexp()&amp;nbsp;should be&amp;nbsp;lot faster than multiply on MCUs without FP coprocessor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Before using it please check ldexp() works well with 0.0 as first argument. I saw few not cheap compilers having implemented it wrong, unexpected results doing something like ldexp(0.0, -30). When first argument is 0.0 should return 0.0 no matter what is 2nd argument.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 May 2019 06:28:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/converting-32-bit-Q1-31-type-to-double/m-p/899333#M22855</guid>
      <dc:creator>kef2</dc:creator>
      <dc:date>2019-05-03T06:28:54Z</dc:date>
    </item>
    <item>
      <title>Re: converting 32-bit Q1.31 type to double</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/converting-32-bit-Q1-31-type-to-double/m-p/899334#M22856</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your reply!&lt;/P&gt;&lt;P&gt;But can we do a direct type casting like&lt;/P&gt;&lt;P&gt;tFrac32 y;&lt;/P&gt;&lt;P&gt;double x ;&lt;/P&gt;&lt;P&gt;x = (double)( y);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 May 2019 07:18:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/converting-32-bit-Q1-31-type-to-double/m-p/899334#M22856</guid>
      <dc:creator>fixed-term_apar</dc:creator>
      <dc:date>2019-05-03T07:18:44Z</dc:date>
    </item>
    <item>
      <title>Re: converting 32-bit Q1.31 type to double</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/converting-32-bit-Q1-31-type-to-double/m-p/899335#M22857</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No, unless compiler supports&amp;nbsp;nonstandard extension and nonstandard tFrac32 type.&amp;nbsp;In C++ you could probably create tFrac32 class and define typecast operator for it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 May 2019 07:59:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/converting-32-bit-Q1-31-type-to-double/m-p/899335#M22857</guid>
      <dc:creator>kef2</dc:creator>
      <dc:date>2019-05-03T07:59:50Z</dc:date>
    </item>
  </channel>
</rss>

