<?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 Float to integer rounding on PowerPC in MPC5xxx</title>
    <link>https://community.nxp.com/t5/MPC5xxx/Float-to-integer-rounding-on-PowerPC/m-p/459144#M1571</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We've used "efsctsi" assembly instruction on MPC5xxx MCU and "fctiw" on MPC83xx PowerQUICC II Pro CPU (having SPEFSCR[FRMC] / FPSCR[RN] = 00 (round to nearest)) and we were surprised of the result. We were expecting the following 32bits floats to be converted to the following integers:&lt;/P&gt;&lt;P&gt;. 6.5 -&amp;gt; expected=7 ; obtained=6&lt;/P&gt;&lt;P&gt;. 7.5 -&amp;gt; expected=8 (obtained that)&lt;/P&gt;&lt;P&gt;. 8.5 -&amp;gt; expected=9 ; obtained=8&lt;/P&gt;&lt;P&gt;. -6.5 -&amp;gt; expected = -7 ; obtained = -6&lt;/P&gt;&lt;P&gt;. -7.5 -&amp;gt; expected = -8 (obtained that)&lt;/P&gt;&lt;P&gt;. -8.5 -&amp;gt; expected = -9 ; obtained = -8&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, is it possible to use these instructions to round floats to integer including round +x.5 to x+1 and -x.5 to -x-1? Or are these instructions performing a base-2 rounding rather than a base-10 rounding?&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 05 Nov 2015 18:41:32 GMT</pubDate>
    <dc:creator>EAlepins</dc:creator>
    <dc:date>2015-11-05T18:41:32Z</dc:date>
    <item>
      <title>Float to integer rounding on PowerPC</title>
      <link>https://community.nxp.com/t5/MPC5xxx/Float-to-integer-rounding-on-PowerPC/m-p/459144#M1571</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We've used "efsctsi" assembly instruction on MPC5xxx MCU and "fctiw" on MPC83xx PowerQUICC II Pro CPU (having SPEFSCR[FRMC] / FPSCR[RN] = 00 (round to nearest)) and we were surprised of the result. We were expecting the following 32bits floats to be converted to the following integers:&lt;/P&gt;&lt;P&gt;. 6.5 -&amp;gt; expected=7 ; obtained=6&lt;/P&gt;&lt;P&gt;. 7.5 -&amp;gt; expected=8 (obtained that)&lt;/P&gt;&lt;P&gt;. 8.5 -&amp;gt; expected=9 ; obtained=8&lt;/P&gt;&lt;P&gt;. -6.5 -&amp;gt; expected = -7 ; obtained = -6&lt;/P&gt;&lt;P&gt;. -7.5 -&amp;gt; expected = -8 (obtained that)&lt;/P&gt;&lt;P&gt;. -8.5 -&amp;gt; expected = -9 ; obtained = -8&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, is it possible to use these instructions to round floats to integer including round +x.5 to x+1 and -x.5 to -x-1? Or are these instructions performing a base-2 rounding rather than a base-10 rounding?&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Nov 2015 18:41:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MPC5xxx/Float-to-integer-rounding-on-PowerPC/m-p/459144#M1571</guid>
      <dc:creator>EAlepins</dc:creator>
      <dc:date>2015-11-05T18:41:32Z</dc:date>
    </item>
    <item>
      <title>Re: Float to integer rounding on PowerPC</title>
      <link>https://community.nxp.com/t5/MPC5xxx/Float-to-integer-rounding-on-PowerPC/m-p/459145#M1572</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I believe it’ll have something to do with hexadecimal representation of float number as this number is rounded up/down/nearest (not its decimal interpretation) if result of calculation is inexact. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have found in some old response following example I think could fit to this situation:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When we do calculation 5.0/3.0 = 1.66666 (round to the nearest)&lt;/P&gt;&lt;P&gt;The actual result is 1.66666 (in HEX 0x3FD55555) although assumption could be 1.66667&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Possible a single-precision HEX result are:&lt;/P&gt;&lt;P&gt;0x3fd55554&lt;/P&gt;&lt;P&gt;0x3fd55555&lt;/P&gt;&lt;P&gt;0x3fd55556&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and converting these possibilities to decimal are:&lt;/P&gt;&lt;P&gt;1.66666651&lt;/P&gt;&lt;P&gt;1.66666663&lt;/P&gt;&lt;P&gt;1.66666675&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1.66666663 is the closest representation to the actual number.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Nov 2015 12:39:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MPC5xxx/Float-to-integer-rounding-on-PowerPC/m-p/459145#M1572</guid>
      <dc:creator>davidtosenovjan</dc:creator>
      <dc:date>2015-11-09T12:39:49Z</dc:date>
    </item>
    <item>
      <title>Re: Float to integer rounding on PowerPC</title>
      <link>https://community.nxp.com/t5/MPC5xxx/Float-to-integer-rounding-on-PowerPC/m-p/459146#M1573</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think you are discussing floating-point number rounding for floating-point operations such as multiplication or division. The PowerPC manuals have doog info on this. However, "efsctsi" / "fctiw" are different. They round the floating-point number to its nearest _integer_, thus we are not discussing rounding of the very last digit of a number, but rounding of all the fractional digits into the lowest integral digit. And this process is not well documented. There is indeed a pseudo code in the annexes of the EREF, but hard to understand... And still, I don't understand why even numbers are wrongly rounded (6.5, 8.5, 10.5) whereas odd numbers are ok (7.5, 9.5, 11.5).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Nov 2015 13:52:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MPC5xxx/Float-to-integer-rounding-on-PowerPC/m-p/459146#M1573</guid>
      <dc:creator>EAlepins</dc:creator>
      <dc:date>2015-11-09T13:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: Float to integer rounding on PowerPC</title>
      <link>https://community.nxp.com/t5/MPC5xxx/Float-to-integer-rounding-on-PowerPC/m-p/459147#M1574</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Could you give me hexadecimal representation of mentioned floating values?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Nov 2015 14:38:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MPC5xxx/Float-to-integer-rounding-on-PowerPC/m-p/459147#M1574</guid>
      <dc:creator>davidtosenovjan</dc:creator>
      <dc:date>2015-11-11T14:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: Float to integer rounding on PowerPC</title>
      <link>https://community.nxp.com/t5/MPC5xxx/Float-to-integer-rounding-on-PowerPC/m-p/459148#M1575</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For example, 6.5 is 0x40D00000. And it is rounded to integer 0x00000006.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Nov 2015 13:28:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MPC5xxx/Float-to-integer-rounding-on-PowerPC/m-p/459148#M1575</guid>
      <dc:creator>EAlepins</dc:creator>
      <dc:date>2015-11-12T13:28:22Z</dc:date>
    </item>
    <item>
      <title>Re: Float to integer rounding on PowerPC</title>
      <link>https://community.nxp.com/t5/MPC5xxx/Float-to-integer-rounding-on-PowerPC/m-p/459149#M1576</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I can confirm observed behavior. I have test with e200z759. It is mode "Round to nearest, ties to even" and it seems to be fixed on this core.&lt;/P&gt;&lt;P&gt;&lt;A href="https://en.wikipedia.org/wiki/IEEE_floating_point#Rounding_rules" title="https://en.wikipedia.org/wiki/IEEE_floating_point#Rounding_rules"&gt;IEEE floating point - Wikipedia, the free encyclopedia&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_0.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/29251iC87125BD594A4D25/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_0.png" alt="pastedImage_0.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;e200z760 has following SPEFSCR[RM] affecting rounding mode. Note that FRMC bit also influence float to integer rounding behavior so here you should be able to configure all options from table above.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_3.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/29468i2640888B87F01A68/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_3.png" alt="pastedImage_3.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_4.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/29594i85B333BF5ED30D05/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_4.png" alt="pastedImage_4.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_0.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/29743iBD28992CFD54148A/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_0.png" alt="pastedImage_0.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Nov 2015 14:18:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MPC5xxx/Float-to-integer-rounding-on-PowerPC/m-p/459149#M1576</guid>
      <dc:creator>davidtosenovjan</dc:creator>
      <dc:date>2015-11-13T14:18:06Z</dc:date>
    </item>
    <item>
      <title>Re: Float to integer rounding on PowerPC</title>
      <link>https://community.nxp.com/t5/MPC5xxx/Float-to-integer-rounding-on-PowerPC/m-p/459150#M1577</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks. So if using e200z760 (which is used in very few MCUs though...), then setting SPEFSCR[RM]=0 and SPEFSCR[FRMC]=00 would fix the problem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Nov 2015 14:39:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MPC5xxx/Float-to-integer-rounding-on-PowerPC/m-p/459150#M1577</guid>
      <dc:creator>EAlepins</dc:creator>
      <dc:date>2015-11-13T14:39:22Z</dc:date>
    </item>
  </channel>
</rss>

