<?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: Is this a bug . strange values in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/is-this-a-bug-strange-values/m-p/8719380#M14398</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5741855"&gt;@BrianEkins&lt;/a&gt;&amp;nbsp; already said, this is related to how floating-point numbers are encoded into memory. See &lt;A href="https://en.wikipedia.org/wiki/IEEE_754" target="_blank" rel="noopener"&gt;IEEE 754&lt;/A&gt; for more information. Most of the time, these numbers are encoded with 64 bits and are represented with 16 decimals.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only problem here is that the last digit of the numbers are incorrect. It's obvious for 3.5 that should be exactly represented as 3.5000000000000000&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a small python code:&lt;/P&gt;
&lt;PRE&gt;X = [2.99, 3.5, 3.707, 3.708]
['{:.16f}'.format(x) for x in X]&lt;/PRE&gt;
&lt;P&gt;And the results:&lt;/P&gt;
&lt;PRE&gt;['2.9900000000000002',
'3.5000000000000000',
'3.7069999999999999',
'3.7080000000000002']&lt;/PRE&gt;
&lt;P&gt;As you can see, these values are different from the ones you reported in the first post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 10 Apr 2019 05:01:54 GMT</pubDate>
    <dc:creator>JeromeBriot</dc:creator>
    <dc:date>2019-04-10T05:01:54Z</dc:date>
    <item>
      <title>Is this a bug . strange values</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/is-this-a-bug-strange-values/m-p/8700263#M14394</link>
      <description>&lt;P&gt;Hi All&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My Add-in has a couple of Value inputs, one for Shank Width (ShankWidth) and one for Stone Diameter (StoneDia), both are in mm&lt;/P&gt;
&lt;P&gt;The values inputed are stored has User Parameters .&lt;/P&gt;
&lt;P&gt;here are a few screen shots &amp;nbsp;both set to 4mm, and you can see the user parameters showing 4mm&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2019-04-02 at 15.22.38.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/621186iA220A6C3082E83F8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screen Shot 2019-04-02 at 15.22.38.png" alt="Screen Shot 2019-04-02 at 15.22.38.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2019-04-02 at 15.23.03.png" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/621187iAAAD69A4E293F305/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2019-04-02 at 15.23.03.png" alt="Screen Shot 2019-04-02 at 15.23.03.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;now with settings set to &amp;nbsp;2mm&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2019-04-02 at 15.23.50.png" style="width: 616px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/621188i107FEC58F0E9D1DC/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2019-04-02 at 15.23.50.png" alt="Screen Shot 2019-04-02 at 15.23.50.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and user parameters&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2019-04-02 at 15.24.08.png" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/621189iDA016DDE3BB12E21/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2019-04-02 at 15.24.08.png" alt="Screen Shot 2019-04-02 at 15.24.08.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if I use any number 3.x number I get this&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2019-04-02 at 15.24.36.png" style="width: 578px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/621190i99C58828B663A227/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2019-04-02 at 15.24.36.png" alt="Screen Shot 2019-04-02 at 15.24.36.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2019-04-02 at 15.24.53.png" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/621191i6AC28E3D29C4E18D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2019-04-02 at 15.24.53.png" alt="Screen Shot 2019-04-02 at 15.24.53.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I entre 3.5 , it will get stored has&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3.5000000000000004&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3.708 and above is store has it's entered&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3.707 becomes&amp;nbsp;3.7070000000000003 mm&lt;/P&gt;
&lt;P&gt;2.999 is fine &amp;nbsp;if I enter 2.9999 it then becomes&amp;nbsp;2.9999000000000002 mm&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which is does not look so good when I read the value back into the input&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2019-04-02 at 15.42.27.png" style="width: 494px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/621193iFEEC4B9E3DECCDB6/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2019-04-02 at 15.42.27.png" alt="Screen Shot 2019-04-02 at 15.42.27.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Has anyone come across this before?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers, Stephen&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2019 05:53:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/is-this-a-bug-strange-values/m-p/8700263#M14394</guid>
      <dc:creator>StephenCim-001</dc:creator>
      <dc:date>2019-04-02T05:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: Is this a bug . strange values</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/is-this-a-bug-strange-values/m-p/8714476#M14395</link>
      <description>&lt;P&gt;Am I right in saying no one has seen this sort of error before?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers, Stephen&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2019 12:25:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/is-this-a-bug-strange-values/m-p/8714476#M14395</guid>
      <dc:creator>StephenCim-001</dc:creator>
      <dc:date>2019-04-08T12:25:39Z</dc:date>
    </item>
    <item>
      <title>Re: Is this a bug . strange values</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/is-this-a-bug-strange-values/m-p/8715535#M14396</link>
      <description>&lt;P&gt;Welcome to the world of floating point numbers and computers.&amp;nbsp; It's not a bug but is just a reflection of how floating point numbers are stored in a computer.&amp;nbsp; I wrote a &lt;A href="https://modthemachine.typepad.com/my_weblog/2013/08/comparing-floating-point-numbers.html" target="_blank" rel="noopener"&gt;post&lt;/A&gt; about this a few years ago illustrating it using Visual Basic.&amp;nbsp; I also just found a good &lt;A href="https://docs.python.org/3/tutorial/floatingpoint.html" target="_blank" rel="noopener"&gt;write-up&lt;/A&gt; in the Python documentation.&amp;nbsp; It's important to note that it's not a programming language issue but just a reflection of the internals of how computers work with floating point numbers.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2019 18:21:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/is-this-a-bug-strange-values/m-p/8715535#M14396</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2019-04-08T18:21:29Z</dc:date>
    </item>
    <item>
      <title>Re: Is this a bug . strange values</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/is-this-a-bug-strange-values/m-p/8717036#M14397</link>
      <description>Thanks Brian

I've added some code to truncate figures to 2 decimal places....   &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;  

Cheers, Stephen</description>
      <pubDate>Tue, 09 Apr 2019 10:15:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/is-this-a-bug-strange-values/m-p/8717036#M14397</guid>
      <dc:creator>StephenCim-001</dc:creator>
      <dc:date>2019-04-09T10:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: Is this a bug . strange values</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/is-this-a-bug-strange-values/m-p/8719380#M14398</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5741855"&gt;@BrianEkins&lt;/a&gt;&amp;nbsp; already said, this is related to how floating-point numbers are encoded into memory. See &lt;A href="https://en.wikipedia.org/wiki/IEEE_754" target="_blank" rel="noopener"&gt;IEEE 754&lt;/A&gt; for more information. Most of the time, these numbers are encoded with 64 bits and are represented with 16 decimals.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only problem here is that the last digit of the numbers are incorrect. It's obvious for 3.5 that should be exactly represented as 3.5000000000000000&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a small python code:&lt;/P&gt;
&lt;PRE&gt;X = [2.99, 3.5, 3.707, 3.708]
['{:.16f}'.format(x) for x in X]&lt;/PRE&gt;
&lt;P&gt;And the results:&lt;/P&gt;
&lt;PRE&gt;['2.9900000000000002',
'3.5000000000000000',
'3.7069999999999999',
'3.7080000000000002']&lt;/PRE&gt;
&lt;P&gt;As you can see, these values are different from the ones you reported in the first post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 05:01:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/is-this-a-bug-strange-values/m-p/8719380#M14398</guid>
      <dc:creator>JeromeBriot</dc:creator>
      <dc:date>2019-04-10T05:01:54Z</dc:date>
    </item>
  </channel>
</rss>

