<?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 MLIB FRAC16 Edgecase in MCUXpresso General</title>
    <link>https://community.nxp.com/t5/MCUXpresso-General/MLIB-FRAC16-Edgecase/m-p/890938#M1748</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I noticed a weird bug / edgecase in the FRAC16 macro defined in "rtcesl/mlib/mlib_types.h" header file. The nested ternary expression appears to implicitly cast the type of the result as the TRUE case for the ternary expression. So when the input is a number less than -1, the default return value of 0x8000 is first cast to a double (32768) and then to a&amp;nbsp;signed short (32767). But we want 0x8000 to be directly cast to a signed short (-32768).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Pretty certain that the fix is to just cast the floating point expression inside the nested ternary expression, ( x )*0x8000, to a frac16_t so that FALSE case of 0x8000 isn't cast to a double first. I've attached a screenshot of a little test in an online C++ shell demonstrating the problem and the proposed fix. The casting shouldn't matter for the positive edge case (0x7FFF) because that resolves to 32767.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since the FRAC32, FRAC64, ACC16, ACC32, ACC64 macros are written the same, they should have this problem as well.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your time!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- Adrian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 24 Apr 2019 14:39:00 GMT</pubDate>
    <dc:creator>ae1</dc:creator>
    <dc:date>2019-04-24T14:39:00Z</dc:date>
    <item>
      <title>MLIB FRAC16 Edgecase</title>
      <link>https://community.nxp.com/t5/MCUXpresso-General/MLIB-FRAC16-Edgecase/m-p/890938#M1748</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I noticed a weird bug / edgecase in the FRAC16 macro defined in "rtcesl/mlib/mlib_types.h" header file. The nested ternary expression appears to implicitly cast the type of the result as the TRUE case for the ternary expression. So when the input is a number less than -1, the default return value of 0x8000 is first cast to a double (32768) and then to a&amp;nbsp;signed short (32767). But we want 0x8000 to be directly cast to a signed short (-32768).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Pretty certain that the fix is to just cast the floating point expression inside the nested ternary expression, ( x )*0x8000, to a frac16_t so that FALSE case of 0x8000 isn't cast to a double first. I've attached a screenshot of a little test in an online C++ shell demonstrating the problem and the proposed fix. The casting shouldn't matter for the positive edge case (0x7FFF) because that resolves to 32767.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since the FRAC32, FRAC64, ACC16, ACC32, ACC64 macros are written the same, they should have this problem as well.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your time!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- Adrian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Apr 2019 14:39:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-General/MLIB-FRAC16-Edgecase/m-p/890938#M1748</guid>
      <dc:creator>ae1</dc:creator>
      <dc:date>2019-04-24T14:39:00Z</dc:date>
    </item>
    <item>
      <title>Re: MLIB FRAC16 Edgecase</title>
      <link>https://community.nxp.com/t5/MCUXpresso-General/MLIB-FRAC16-Edgecase/m-p/890939#M1749</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;Please let us know your chip part number, thus we can ask the related engineer to look into this issue.&lt;/P&gt;&lt;P&gt;You are using MCUXpresso IDE right?&lt;/P&gt;&lt;P&gt;Jun Zhang&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Apr 2019 06:02:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-General/MLIB-FRAC16-Edgecase/m-p/890939#M1749</guid>
      <dc:creator>ZhangJennie</dc:creator>
      <dc:date>2019-04-29T06:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: MLIB FRAC16 Edgecase</title>
      <link>https://community.nxp.com/t5/MCUXpresso-General/MLIB-FRAC16-Edgecase/m-p/890940#M1750</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Jun,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The chip is the&amp;nbsp;MKV31F512VLL12P, and we are using the MCUXpresso IDE.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- Adrian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2019 19:15:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-General/MLIB-FRAC16-Edgecase/m-p/890940#M1750</guid>
      <dc:creator>ae1</dc:creator>
      <dc:date>2019-04-30T19:15:56Z</dc:date>
    </item>
    <item>
      <title>Re: MLIB FRAC16 Edgecase</title>
      <link>https://community.nxp.com/t5/MCUXpresso-General/MLIB-FRAC16-Edgecase/m-p/890941#M1751</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Adrian,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for reporting this issue. Your feedback is highly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Felipe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 May 2019 19:46:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-General/MLIB-FRAC16-Edgecase/m-p/890941#M1751</guid>
      <dc:creator>FelipeGarcia</dc:creator>
      <dc:date>2019-05-03T19:46:41Z</dc:date>
    </item>
    <item>
      <title>Re: MLIB FRAC16 Edgecase</title>
      <link>https://community.nxp.com/t5/MCUXpresso-General/MLIB-FRAC16-Edgecase/m-p/890942#M1752</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;We looked a bit more into the behavior of the C++ ternary operator. If the second and third operands are of different types, then the processor attempts to convert both operands to a common type. For a&amp;nbsp;double and an int, the common type is a double, because an int can be converted to a&amp;nbsp;double without loss of information. So since the second operand,&amp;nbsp;(x)*0x8000, is a double, the third operand,&amp;nbsp;0x8000, is implicitly converted to a double first when the expression is evaluated.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 May 2019 20:25:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-General/MLIB-FRAC16-Edgecase/m-p/890942#M1752</guid>
      <dc:creator>ae1</dc:creator>
      <dc:date>2019-05-03T20:25:14Z</dc:date>
    </item>
    <item>
      <title>Re: MLIB FRAC16 Edgecase</title>
      <link>https://community.nxp.com/t5/MCUXpresso-General/MLIB-FRAC16-Edgecase/m-p/890943#M1753</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Adrian,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;According to what you mention, the modifications you did to the macros are correct. Casting &lt;STRONG&gt;(x)*0x8000&lt;/STRONG&gt; to a &lt;STRONG&gt;short&lt;/STRONG&gt; type will prevent the ternary operator to convert &lt;STRONG&gt;0x8000&lt;/STRONG&gt; to a&lt;STRONG&gt; double&lt;/STRONG&gt; first.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Felipe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 May 2019 21:09:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-General/MLIB-FRAC16-Edgecase/m-p/890943#M1753</guid>
      <dc:creator>FelipeGarcia</dc:creator>
      <dc:date>2019-05-06T21:09:45Z</dc:date>
    </item>
    <item>
      <title>Re: MLIB FRAC16 Edgecase</title>
      <link>https://community.nxp.com/t5/MCUXpresso-General/MLIB-FRAC16-Edgecase/m-p/1152285#M3933</link>
      <description>&lt;P&gt;This was a major bug. Please issue an update to the RTCESL.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2020 18:47:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-General/MLIB-FRAC16-Edgecase/m-p/1152285#M3933</guid>
      <dc:creator>aberger</dc:creator>
      <dc:date>2020-09-11T18:47:39Z</dc:date>
    </item>
  </channel>
</rss>

