<?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>Classic/Legacy CodeWarriorのトピックRe: Unpredictable Math -- Can't Divide Long Ints???</title>
    <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Unpredictable-Math-Can-t-Divide-Long-Ints/m-p/133985#M685</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;If the value of long_speed = 5000L, the first equation results&amp;nbsp; in pulsetime = 968.&amp;nbsp; Since when does 5000/1000 = 968???.&amp;nbsp; What can I do to get the math to work?&amp;nbsp; I already tried doubling the stack.&lt;/DIV&gt;&lt;DIV&gt;I tried making the 1000 1000.0.&amp;nbsp; I tried way too many things just to get a very simple division to work.&lt;/DIV&gt;&lt;DIV&gt;Does anyone have a clue?&amp;nbsp; Is there a codewarrior compiler guru out there?&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I agree you should probably take a look at the assembly.&amp;nbsp; Is DEF_INT_RATE a #define?&amp;nbsp; This maybe part of the problem.&amp;nbsp; The reason is you are casting pulsetime as a uint on the return...this could cause some unwanted optimization.&amp;nbsp; First try a #pragma around the function to turn off optimization and make sure DEF_INT_RATE is a const ulong not a #define.&amp;nbsp; You might also try returning pulsetime as a ulong rather than a uint to see what is going on.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;If you can you might want to bit shift rather than divide...roundoff errors can be murderous.&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 25 Oct 2006 12:27:32 GMT</pubDate>
    <dc:creator>Marreshe</dc:creator>
    <dc:date>2006-10-25T12:27:32Z</dc:date>
    <item>
      <title>Unpredictable Math -- Can't Divide Long Ints???</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Unpredictable-Math-Can-t-Divide-Long-Ints/m-p/133983#M683</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;This is making me insane.&amp;nbsp; I am trying to divide a long by a constant and I can't get the compiler to do it.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;unsigned int do_math(ulong long_speed)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;ulong pulsetime = (long_speed/1000L);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;pulsetime = (1000L/pulsetime);&lt;BR /&gt;&amp;nbsp;pulsetime /= DEF_INT_RATE;&amp;nbsp; // interupt rate&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;return &amp;nbsp;(uint)pulsetime;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;}&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;If the value of long_speed = 5000L, the first equation results&amp;nbsp; in pulsetime = 968.&amp;nbsp; Since when does 5000/1000 = 968???.&amp;nbsp; What can I do to get the math to work?&amp;nbsp; I already tried doubling the stack.&lt;/DIV&gt;&lt;DIV&gt;I tried making the 1000 1000.0.&amp;nbsp; I tried way too many things just to get a very simple division to work.&lt;/DIV&gt;&lt;DIV&gt;Does anyone have a clue?&amp;nbsp; Is there a codewarrior compiler guru out there?&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Oct 2006 21:50:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Unpredictable-Math-Can-t-Divide-Long-Ints/m-p/133983#M683</guid>
      <dc:creator>mel</dc:creator>
      <dc:date>2006-10-23T21:50:33Z</dc:date>
    </item>
    <item>
      <title>Re: Unpredictable Math -- Can't Divide Long Ints???</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Unpredictable-Math-Can-t-Divide-Long-Ints/m-p/133984#M684</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;as I don't see the problem, so just some questions and hints.&lt;BR /&gt;- The "1000L/pulsetime" could be a division by zero, you should handle this case, I guess.&lt;BR /&gt;- well, as long as it does not work, its not so important, but it looks like everything except the first division could be performed with (unsigned) int arithmetic.&lt;BR /&gt;- for which target/cpu is this? Which tools do you use?&lt;BR /&gt;- can you provide a complete compilable source code, possibly with the disassembly listing and with one usage which fails?&lt;BR /&gt;(what is DEF_INT_RATE?)&lt;BR /&gt;- are you sure this is a functional problem and not a debug info only problem?&lt;BR /&gt;- check the preprocessor output. Does not look like this is your problem, but in the end you never know.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Oct 2006 05:16:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Unpredictable-Math-Can-t-Divide-Long-Ints/m-p/133984#M684</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2006-10-24T05:16:31Z</dc:date>
    </item>
    <item>
      <title>Re: Unpredictable Math -- Can't Divide Long Ints???</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Unpredictable-Math-Can-t-Divide-Long-Ints/m-p/133985#M685</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;If the value of long_speed = 5000L, the first equation results&amp;nbsp; in pulsetime = 968.&amp;nbsp; Since when does 5000/1000 = 968???.&amp;nbsp; What can I do to get the math to work?&amp;nbsp; I already tried doubling the stack.&lt;/DIV&gt;&lt;DIV&gt;I tried making the 1000 1000.0.&amp;nbsp; I tried way too many things just to get a very simple division to work.&lt;/DIV&gt;&lt;DIV&gt;Does anyone have a clue?&amp;nbsp; Is there a codewarrior compiler guru out there?&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I agree you should probably take a look at the assembly.&amp;nbsp; Is DEF_INT_RATE a #define?&amp;nbsp; This maybe part of the problem.&amp;nbsp; The reason is you are casting pulsetime as a uint on the return...this could cause some unwanted optimization.&amp;nbsp; First try a #pragma around the function to turn off optimization and make sure DEF_INT_RATE is a const ulong not a #define.&amp;nbsp; You might also try returning pulsetime as a ulong rather than a uint to see what is going on.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;If you can you might want to bit shift rather than divide...roundoff errors can be murderous.&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Oct 2006 12:27:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Unpredictable-Math-Can-t-Divide-Long-Ints/m-p/133985#M685</guid>
      <dc:creator>Marreshe</dc:creator>
      <dc:date>2006-10-25T12:27:32Z</dc:date>
    </item>
  </channel>
</rss>

