<?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 Re: float to double casting issue in Classic/Legacy CodeWarrior</title>
    <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/float-to-double-casting-issue/m-p/136353#M925</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Why is it directly representable if I assign it directly, but not if I convert it using the cast?&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;What is the point of using a double if it can not at least represent the equivalent precision of a float?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks!&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 18 May 2006 19:16:28 GMT</pubDate>
    <dc:creator>BobS</dc:creator>
    <dc:date>2006-05-18T19:16:28Z</dc:date>
    <item>
      <title>float to double casting issue</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/float-to-double-casting-issue/m-p/136351#M923</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt;I am trying to do a calculation where I need to convert a float number to a double to obtain added precision in a chain calculation.&amp;nbsp; I seem to have encountered a problem.&amp;nbsp; It appears that the following does not work as expected:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;float TestFloat;&lt;/DIV&gt;&lt;DIV&gt;double Test;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;TestFloat = 20.03564;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Test = (double)TestFloat;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;When I look in the debugger, TestFloat shows the correct value.&amp;nbsp; But, Test shows a value of 20.035642623901367.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;If I&amp;nbsp;run the following:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Test = 20.03564;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The debugger shows the exact value as a double.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;What is happening?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks!&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 May 2006 02:17:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/float-to-double-casting-issue/m-p/136351#M923</guid>
      <dc:creator>BobS</dc:creator>
      <dc:date>2006-05-18T02:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: float to double casting issue</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/float-to-double-casting-issue/m-p/136352#M924</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;The point is that 20.03564 is not exactly represantible as float. Therefore when you first assign it to a float then this float to a double, the result cannot be more precise than the float representation.&lt;BR /&gt;When you directly assign the 20.03564 value to the double, you do get diretly double precision.&lt;BR /&gt;So to me, the observed behaviour is just what I would expect.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 May 2006 04:37:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/float-to-double-casting-issue/m-p/136352#M924</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2006-05-18T04:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: float to double casting issue</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/float-to-double-casting-issue/m-p/136353#M925</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Why is it directly representable if I assign it directly, but not if I convert it using the cast?&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;What is the point of using a double if it can not at least represent the equivalent precision of a float?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks!&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 May 2006 19:16:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/float-to-double-casting-issue/m-p/136353#M925</guid>
      <dc:creator>BobS</dc:creator>
      <dc:date>2006-05-18T19:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: float to double casting issue</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/float-to-double-casting-issue/m-p/136354#M926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;20.03564 is not exactly representable as double or a float. That they are printed in the debugger this way, just means that the stored value is a close approximation of it, but it is impossible that the stored value is exactly 20.0356400000000000000000000000000000000000000000000000000000000000000000000000000000.&lt;BR /&gt;&lt;BR /&gt;When you print the float or the double, and you get the same text representation, this does not mean that the float and the double are identical.&lt;BR /&gt;No, the double representation is much more close to the value you specify, but as all the additional digits happen to be 0, they are not printed.&lt;BR /&gt;For the float, there is just no reason to print more digits, as those are not significant, given the float resolution.&lt;BR /&gt;Maybe you should not use just a short 7 digits number like 20.03564 to see the difference double makes. Use something with more digits, like 20.0356412345678901234567890123456789012345678901234567890&lt;BR /&gt;Here you will loose something in any case.&lt;BR /&gt;Also note that the value printed by the debugger is also just an appriximation of the actual stored value.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 May 2006 02:17:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/float-to-double-casting-issue/m-p/136354#M926</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2006-05-19T02:17:43Z</dc:date>
    </item>
    <item>
      <title>Re: float to double casting issue</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/float-to-double-casting-issue/m-p/136355#M927</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Thank you for your help!&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 May 2006 19:11:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/float-to-double-casting-issue/m-p/136355#M927</guid>
      <dc:creator>BobS</dc:creator>
      <dc:date>2006-05-19T19:11:24Z</dc:date>
    </item>
  </channel>
</rss>

