<?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>Kinetis Design StudioのトピックRe: Negative float value print</title>
    <link>https://community.nxp.com/t5/Kinetis-Design-Studio/Negative-float-value-print/m-p/580035#M7375</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Martin,&lt;/P&gt;&lt;P&gt;There is bug in the fsl_debug_console.c (look below for "//DES" comment).&lt;/P&gt;&lt;P&gt;static int32_t DbgConsole_ConvertFloatRadixNumToString(char *numstr,&lt;BR /&gt; void *nump,&lt;BR /&gt; int32_t radix,&lt;BR /&gt; uint32_t precision_width)&lt;BR /&gt;{&lt;BR /&gt; int32_t a;&lt;BR /&gt; int32_t b;&lt;BR /&gt; int32_t c;&lt;BR /&gt; int32_t i;&lt;BR /&gt; uint32_t uc;&lt;BR /&gt; double fa;&lt;BR /&gt; double dc;&lt;BR /&gt; double fb;&lt;BR /&gt; double r;&lt;BR /&gt; double fractpart;&lt;BR /&gt; double intpart;&lt;/P&gt;&lt;P&gt;int32_t nlen;&lt;BR /&gt; char *nstrp;&lt;BR /&gt; nlen = 0;&lt;BR /&gt; nstrp = numstr;&lt;BR /&gt; *nstrp++ = '\0';&lt;BR /&gt; r = *(double *)nump;&lt;BR /&gt; if (!r)&lt;BR /&gt; {&lt;BR /&gt; *nstrp = '0';&lt;BR /&gt; ++nlen;&lt;BR /&gt; return nlen;&lt;BR /&gt; }&lt;BR /&gt; fractpart = modf((double)r, (double *)&amp;amp;intpart);&lt;BR /&gt; /* Process fractional part. */&lt;BR /&gt; for (i = 0; i &amp;lt; precision_width; i++)&lt;BR /&gt; {&lt;BR /&gt; fractpart *= radix;&lt;BR /&gt; }&lt;BR /&gt; if (r &amp;gt;= 0)&lt;BR /&gt; {&lt;BR /&gt; fa = fractpart + (double)0.5;&lt;BR /&gt; if (fa &amp;gt;= pow(10, precision_width))&lt;BR /&gt; {&lt;BR /&gt; fractpart++; //DES was intpart++;&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; else&lt;BR /&gt; {&lt;BR /&gt; fa = fractpart - (double)0.5; //DES???&lt;BR /&gt; if (fa &amp;lt;= pow(-10, precision_width))&lt;BR /&gt; {&lt;BR /&gt; fractpart--; //DES was intpart--;&lt;BR /&gt; }&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;Please see solution on this post:&amp;nbsp;&lt;A href="https://community.nxp.com/thread/396034"&gt;PRINTF in KDS&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;David&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 31 Aug 2016 15:45:51 GMT</pubDate>
    <dc:creator>DavidS</dc:creator>
    <dc:date>2016-08-31T15:45:51Z</dc:date>
    <item>
      <title>Negative float value print</title>
      <link>https://community.nxp.com/t5/Kinetis-Design-Studio/Negative-float-value-print/m-p/580033#M7373</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi in KDS 3.2 and latest SDK for K64F, this code:&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;double var1 = -5.8;&lt;/P&gt;&lt;P&gt;PRINTF("%f\r\n", var1);&lt;/P&gt;&lt;P&gt;double var2 = -10.4;&lt;/P&gt;&lt;P&gt;PRINTF("%f\r\n, var2);&lt;/P&gt;&lt;P&gt;double var3 = 1.5;&lt;/P&gt;&lt;P&gt;PRINTF("%f\r\n", var3);&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;produces:&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-6.8&lt;/P&gt;&lt;P&gt;-11.4&lt;/P&gt;&lt;P&gt;1.5&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i.e. negative double numbers are printed with -1 added to them. Why and how to fix it?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Aug 2016 13:20:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Design-Studio/Negative-float-value-print/m-p/580033#M7373</guid>
      <dc:creator>martindusek</dc:creator>
      <dc:date>2016-08-31T13:20:39Z</dc:date>
    </item>
    <item>
      <title>Re: Negative float value print</title>
      <link>https://community.nxp.com/t5/Kinetis-Design-Studio/Negative-float-value-print/m-p/580034#M7374</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;we are using "%ld" for same application&lt;/P&gt;&lt;P&gt;so&lt;/P&gt;&lt;P&gt;can you try with "%ld " rather than "%f"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Aug 2016 14:12:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Design-Studio/Negative-float-value-print/m-p/580034#M7374</guid>
      <dc:creator>harshpatel</dc:creator>
      <dc:date>2016-08-31T14:12:45Z</dc:date>
    </item>
    <item>
      <title>Re: Negative float value print</title>
      <link>https://community.nxp.com/t5/Kinetis-Design-Studio/Negative-float-value-print/m-p/580035#M7375</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Martin,&lt;/P&gt;&lt;P&gt;There is bug in the fsl_debug_console.c (look below for "//DES" comment).&lt;/P&gt;&lt;P&gt;static int32_t DbgConsole_ConvertFloatRadixNumToString(char *numstr,&lt;BR /&gt; void *nump,&lt;BR /&gt; int32_t radix,&lt;BR /&gt; uint32_t precision_width)&lt;BR /&gt;{&lt;BR /&gt; int32_t a;&lt;BR /&gt; int32_t b;&lt;BR /&gt; int32_t c;&lt;BR /&gt; int32_t i;&lt;BR /&gt; uint32_t uc;&lt;BR /&gt; double fa;&lt;BR /&gt; double dc;&lt;BR /&gt; double fb;&lt;BR /&gt; double r;&lt;BR /&gt; double fractpart;&lt;BR /&gt; double intpart;&lt;/P&gt;&lt;P&gt;int32_t nlen;&lt;BR /&gt; char *nstrp;&lt;BR /&gt; nlen = 0;&lt;BR /&gt; nstrp = numstr;&lt;BR /&gt; *nstrp++ = '\0';&lt;BR /&gt; r = *(double *)nump;&lt;BR /&gt; if (!r)&lt;BR /&gt; {&lt;BR /&gt; *nstrp = '0';&lt;BR /&gt; ++nlen;&lt;BR /&gt; return nlen;&lt;BR /&gt; }&lt;BR /&gt; fractpart = modf((double)r, (double *)&amp;amp;intpart);&lt;BR /&gt; /* Process fractional part. */&lt;BR /&gt; for (i = 0; i &amp;lt; precision_width; i++)&lt;BR /&gt; {&lt;BR /&gt; fractpart *= radix;&lt;BR /&gt; }&lt;BR /&gt; if (r &amp;gt;= 0)&lt;BR /&gt; {&lt;BR /&gt; fa = fractpart + (double)0.5;&lt;BR /&gt; if (fa &amp;gt;= pow(10, precision_width))&lt;BR /&gt; {&lt;BR /&gt; fractpart++; //DES was intpart++;&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; else&lt;BR /&gt; {&lt;BR /&gt; fa = fractpart - (double)0.5; //DES???&lt;BR /&gt; if (fa &amp;lt;= pow(-10, precision_width))&lt;BR /&gt; {&lt;BR /&gt; fractpart--; //DES was intpart--;&lt;BR /&gt; }&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;Please see solution on this post:&amp;nbsp;&lt;A href="https://community.nxp.com/thread/396034"&gt;PRINTF in KDS&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;David&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Aug 2016 15:45:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Design-Studio/Negative-float-value-print/m-p/580035#M7375</guid>
      <dc:creator>DavidS</dc:creator>
      <dc:date>2016-08-31T15:45:51Z</dc:date>
    </item>
    <item>
      <title>Re: Negative float value print</title>
      <link>https://community.nxp.com/t5/Kinetis-Design-Studio/Negative-float-value-print/m-p/580036#M7376</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Interestingly, I applied this fix last summer in order to fix the off-by-one error when printing negative floats. &amp;nbsp;However, I've just noticed another corner case:&lt;/P&gt;&lt;P&gt;PRINTF("%4.1f\r\n", 7.94); // ----- displays "7.9" as you'd expect&lt;BR /&gt; PRINTF("%4.1f\r\n", 7.96); // ----- displays "7.0" instead of 8.0&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Feb 2017 23:53:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Design-Studio/Negative-float-value-print/m-p/580036#M7376</guid>
      <dc:creator>cwpaynter</dc:creator>
      <dc:date>2017-02-16T23:53:00Z</dc:date>
    </item>
  </channel>
</rss>

