<?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>MCUXpresso IDEのトピックRedlib trunc() unexpectedly returns 0</title>
    <link>https://community.nxp.com/t5/MCUXpresso-IDE/Redlib-trunc-unexpectedly-returns-0/m-p/719158#M1092</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;Hi there,&lt;/P&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;I observe an unexpected result when using &lt;SPAN style="font-family: 'andale mono', monospace;"&gt;trunc().&lt;/SPAN&gt;&amp;nbsp;I wonder if anybody could help me using Redlib with floats and libm.&lt;/P&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;&lt;/P&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;Compiling, linking using &lt;STRONG&gt;Redlib&lt;/STRONG&gt; and debugging&lt;/P&gt;&lt;PRE class="language-c line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="property macro token"&gt;#include &lt;SPAN class="string token"&gt;&amp;lt;math.h&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;int&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;main&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;void&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;

&amp;nbsp; &lt;SPAN class="keyword token"&gt;float&lt;/SPAN&gt; adc_read &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;123.123&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp; &lt;SPAN class="keyword token"&gt;int&lt;/SPAN&gt; adc_int &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;trunc&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;adc_read&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
‍‍
&amp;nbsp; &lt;SPAN class="comment token"&gt;//...enter infinite loop or other code&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;will give me the a value of 0 for &lt;SPAN style="font-family: 'andale mono', monospace;"&gt;adc_int&lt;/SPAN&gt; (see attached screenshot).&lt;SPAN class="lia-inline-image-display-wrapper" image-alt="Capture trunc debug.png"&gt;&lt;IMG alt="Capture trunc debug.png" src="https://community.nxp.com/t5/image/serverpage/image-id/43563i4924E3C1336FB647/image-size/large?v=v2&amp;amp;px=999" title="Capture trunc debug.png" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I link using &lt;STRONG&gt;Newlib&lt;/STRONG&gt; instead, trunc() returns the correct result of 123.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As a workaround, I'm now using a cast to int instead:&lt;/P&gt;&lt;PRE class="language-c line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;int&lt;/SPAN&gt; adc_int &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;int&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;adc_read&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;But still I'm puzzled why Redlib's trunc() returns 0?&lt;/STRONG&gt; What am I missing here? According to &lt;A _jive_internal="true" href="https://community.nxp.com/thread/470197#comment-987947" rel="noopener noreferrer" target="_blank"&gt;LPCXsupport, "Redlib is just a C library"&lt;/A&gt;&amp;nbsp;and therefore I assume it should implement at least functionality &lt;A _jive_internal="true" href="https://community.nxp.com/thread/424432" rel="noopener noreferrer" target="_blank"&gt;according to C90 standard&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 02 Nov 2020 14:02:00 GMT</pubDate>
    <dc:creator>danielholala</dc:creator>
    <dc:date>2020-11-02T14:02:00Z</dc:date>
    <item>
      <title>Redlib trunc() unexpectedly returns 0</title>
      <link>https://community.nxp.com/t5/MCUXpresso-IDE/Redlib-trunc-unexpectedly-returns-0/m-p/719158#M1092</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;Hi there,&lt;/P&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;I observe an unexpected result when using &lt;SPAN style="font-family: 'andale mono', monospace;"&gt;trunc().&lt;/SPAN&gt;&amp;nbsp;I wonder if anybody could help me using Redlib with floats and libm.&lt;/P&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;&lt;/P&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;Compiling, linking using &lt;STRONG&gt;Redlib&lt;/STRONG&gt; and debugging&lt;/P&gt;&lt;PRE class="language-c line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="property macro token"&gt;#include &lt;SPAN class="string token"&gt;&amp;lt;math.h&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;int&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;main&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;void&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;

&amp;nbsp; &lt;SPAN class="keyword token"&gt;float&lt;/SPAN&gt; adc_read &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;123.123&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp; &lt;SPAN class="keyword token"&gt;int&lt;/SPAN&gt; adc_int &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;trunc&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;adc_read&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
‍‍
&amp;nbsp; &lt;SPAN class="comment token"&gt;//...enter infinite loop or other code&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;will give me the a value of 0 for &lt;SPAN style="font-family: 'andale mono', monospace;"&gt;adc_int&lt;/SPAN&gt; (see attached screenshot).&lt;SPAN class="lia-inline-image-display-wrapper" image-alt="Capture trunc debug.png"&gt;&lt;IMG alt="Capture trunc debug.png" src="https://community.nxp.com/t5/image/serverpage/image-id/43563i4924E3C1336FB647/image-size/large?v=v2&amp;amp;px=999" title="Capture trunc debug.png" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I link using &lt;STRONG&gt;Newlib&lt;/STRONG&gt; instead, trunc() returns the correct result of 123.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As a workaround, I'm now using a cast to int instead:&lt;/P&gt;&lt;PRE class="language-c line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;int&lt;/SPAN&gt; adc_int &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;int&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;adc_read&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;But still I'm puzzled why Redlib's trunc() returns 0?&lt;/STRONG&gt; What am I missing here? According to &lt;A _jive_internal="true" href="https://community.nxp.com/thread/470197#comment-987947" rel="noopener noreferrer" target="_blank"&gt;LPCXsupport, "Redlib is just a C library"&lt;/A&gt;&amp;nbsp;and therefore I assume it should implement at least functionality &lt;A _jive_internal="true" href="https://community.nxp.com/thread/424432" rel="noopener noreferrer" target="_blank"&gt;according to C90 standard&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Nov 2020 14:02:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-IDE/Redlib-trunc-unexpectedly-returns-0/m-p/719158#M1092</guid>
      <dc:creator>danielholala</dc:creator>
      <dc:date>2020-11-02T14:02:00Z</dc:date>
    </item>
    <item>
      <title>Re: Redlib trunc() unexpectedly returns 0</title>
      <link>https://community.nxp.com/t5/MCUXpresso-IDE/Redlib-trunc-unexpectedly-returns-0/m-p/719159#M1093</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="color: #51626f; border: 0px;"&gt;So trunc() is a C99 function and one that Redlib unfortunately doesn't currently implement. So I'm intrigued as to how you even got your project to build against Redlib - unless something else in your setup is providing it.&lt;/P&gt;&lt;P style="color: #51626f; border: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="color: #51626f; border: 0px;"&gt;You should also note that where available, trunc() returns a double, not an int:&lt;/P&gt;&lt;P style="color: #51626f; border: 0px;"&gt;&lt;A class="" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.cplusplus.com%2Freference%2Fcmath%2Ftrunc%2F%3Fkw%3Dtrunc" rel="nofollow" style="color: #5e89c1; border: 0px; font-weight: inherit; padding: 0px calc(12px + 0.35ex) 0px 0px;" target="_blank"&gt;http://www.cplusplus.com/reference/cmath/trunc/?kw=trunc&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="color: #51626f; border: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="color: #51626f; border: 0px;"&gt;Regards,&lt;/P&gt;&lt;P style="color: #51626f; border: 0px;"&gt;MCUXpresso IDE Support&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 May 2018 08:32:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-IDE/Redlib-trunc-unexpectedly-returns-0/m-p/719159#M1093</guid>
      <dc:creator>lpcxpresso_supp</dc:creator>
      <dc:date>2018-05-03T08:32:21Z</dc:date>
    </item>
  </channel>
</rss>

