<?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: iLogic says equal number are not equal?? in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8441969#M81367</link>
    <description>&lt;P&gt;Just for fun, I found this site... try your numbers in this and see why they aren't perfect. (make sure to pick some of the binary options for the output)&amp;nbsp;&lt;A href="https://www.exploringbinary.com/floating-point-converter/" target="_blank"&gt;https://www.exploringbinary.com/floating-point-converter/&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 03 Dec 2018 20:00:20 GMT</pubDate>
    <dc:creator>clutsa</dc:creator>
    <dc:date>2018-12-03T20:00:20Z</dc:date>
    <item>
      <title>iLogic says equal number are not equal??</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8437630#M81353</link>
      <description>&lt;P&gt;I often have iLogic rules check if a parameter equals a value, in order to take some appropriate action.&amp;nbsp;This is the kind of if/then test that needs to be very reliable, and you would think it would be -- just checking if one number equals another. However, sometimes I'll run an equality test and the iLogic will say that the two numbers are not equal, when in fact they are.&amp;nbsp;I've&amp;nbsp;run into this strange glitch multiple times before, and thought I'd post to try and find out what the heck is going on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I put together a quick script to demonstrate the issue.&amp;nbsp;To reproduce, first create a new Part and create a parameter in the Part called "d0". Then paste the following rule into the Part and run it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;oSetVal = 1.23456789

Parameter("d0") = oSetVal

IsEqual = If(Parameter("d0") = oSetVal,True,False)
		
MessageBox.Show( _
	"Parameter: " &amp;amp; Parameter("d0") &amp;amp; vbCrLf &amp;amp; _
	"Set value: " &amp;amp; oSetVal &amp;amp; vbCrLf &amp;amp; _
	"Equal: " &amp;amp; IsEqual )&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The rule literally sets the parameter equal to the value, and a message box confirms that they are indeed equal, and yet an equality test says the values are not equal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can experiment with different numbers and see that most of the time, the code returns the correct "True" result. However, for some oddball values, it says they're not equal, even though they are. (Most numbers following the pattern 3.456789, 4.56789, etc. on up to 7.89 also exhibit the glitch).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What's the reason for this? Is there some way to fix this so I can be confident my parameter equality tests in iLogic rules will actually return the correct result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Running Inventor 2017.4.6 on a Lenovo Windows 10 64-bit&amp;nbsp;desktop&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2018 22:04:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8437630#M81353</guid>
      <dc:creator>DRoam</dc:creator>
      <dc:date>2018-11-30T22:04:48Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic says equal number are not equal??</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8437647#M81354</link>
      <description>&lt;P&gt;Here's another version of the rule that makes it easier to test different values and gives better visual feedback of the true/false result with a message box icon:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Do
	oSetVal = InputBox("Enter a Set Value:","Set Value",Parameter("d0"))
	
	If oSetVal = "" Then Exit Do
	
	Parameter("d0") = oSetVal
	
	IsEqual = If(Parameter("d0") = oSetVal,True,False)
	
	oIcon = If(IsEqual,MessageBoxIcon.Information,MessageBoxIcon.Exclamation)
		
	oAnswer = MessageBox.Show( _
		"Parameter: " &amp;amp; Parameter("d0") &amp;amp; vbCrLf &amp;amp; _
		"Set value: " &amp;amp; oSetVal &amp;amp; vbCrLf &amp;amp; _
		"Equal: " &amp;amp; IsEqual _
		,"Result",MessageBoxButtons.OKCancel,oIcon)
Loop Until oAnswer = vbCancel&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Nov 2018 22:16:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8437647#M81354</guid>
      <dc:creator>DRoam</dc:creator>
      <dc:date>2018-11-30T22:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic says equal number are not equal??</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8438076#M81355</link>
      <description>&lt;P&gt;Search ‘iLogic Lies Excitech’ in Google and my blog on this topic may help?&lt;/P&gt;
&lt;P&gt;Luke&lt;/P&gt;</description>
      <pubDate>Sat, 01 Dec 2018 08:19:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8438076#M81355</guid>
      <dc:creator>LukeDavenport</dc:creator>
      <dc:date>2018-12-01T08:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic says equal number are not equal??</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8438444#M81356</link>
      <description>&lt;P&gt;Hi Luke, thanks for directing me to that article and related thread. Glad I'm not alone in this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately, though, the (best) solution in your video was to use the API to get and compare the parameter's value, and unfortunately that's the method I was actually using when I ran into this issue. I just used the normal iLogic Parameter("x") method in my example to simplify things, after double-checking that the issue occurs when doing that, too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please take a look at the revised code below, which uses both methods -- the API access method, and the normal Parameter("x") method. If you try the values I mentioned in my first post (like 1.23456789, or 7.89), both the API method and normal method say the values are not equal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Dim oPartDoc As PartDocument = ThisDoc.Document
Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
Dim oParam As Parameter = oCompDef.Parameters("d0")

Do
	oSetVal = InputBox("Enter a Set Value:","Set Value",Parameter("d0"))
	
	If oSetVal = "" Then Exit Do
	
	Parameter("d0") = oSetVal
	
	oParamValAPI = oParam.Value / 2.54
	oDiffAPI = oParamValAPI-oSetVal
	
	IsEqualAPI = If(oParamValAPI = oSetVal,True,False)
	
	oIcon = If (IsEqualAPI, MessageBoxIcon.Information, MessageBoxIcon.Exclamation)
	
	oParamValNormal = Parameter("d0")
	oDiffNormal = oParamValNormal-oSetVal
	
	IsEqualNormal = If(oParamValNormal = oSetVal,True,False)
	
	oAnswer = MessageBox.Show( _
		"Set value: " &amp;amp; oSetVal &amp;amp; vbCrLf &amp;amp; _
		"API Param Equal: " &amp;amp; IsEqualAPI &amp;amp; vbCrLf &amp;amp; _
		"API Param Difference: " &amp;amp; oDiffAPI &amp;amp; vbCrLf &amp;amp; _
		vbCrLf &amp;amp; _
		"Normal Param Equal: " &amp;amp; IsEqualNormal &amp;amp; vbCrLf &amp;amp; _
		"Normal Param Difference: " &amp;amp; oDiffNormal &amp;amp; vbCrLf _
		,"Result",MessageBoxButtons.RetryCancel,oIcon)
Loop Until oAnswer = vbCancel&lt;/PRE&gt;
&lt;P&gt;Do you still think this could be the same root-cause issue as in your article and the other thread? Or is this something different?&lt;/P&gt;</description>
      <pubDate>Sat, 01 Dec 2018 15:33:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8438444#M81356</guid>
      <dc:creator>DRoam</dc:creator>
      <dc:date>2018-12-01T15:33:00Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic says equal number are not equal??</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8438469#M81357</link>
      <description>&lt;P&gt;Another thing I don't understand, is&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/537534"&gt;@MjDeck&lt;/a&gt;&amp;nbsp;says that iLogic does all of the math operations in double precision (15 decimal places) and does comparisons in decimal precision (7 decimal places). Ok, that sounds like it could definitely cause a glitch like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, here's the math for a number like 440.25 (one of the lowest-precision numbers I've seen that produce the glitch):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Input value: exactly 440.25&lt;/P&gt;
&lt;P&gt;To database units: 440.25 * 2.54 = exactly 1118.235&lt;/P&gt;
&lt;P&gt;Output - back to working units: 1118.235 / 2.54 = exactly 440.25&lt;/P&gt;
&lt;P&gt;Output - Input = 440.25 - 440.25 = 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nowhere in that series of calculations is there a decimal number with digits past 7 decimal places. The highest number of decimal places necessary to perform those calculations is only 3. So even if you only did the math operations AND comparison to 3-decimal-place precision, the input value should still equal the output value. There shouldn't be a difference between the input and output of&amp;nbsp;5.6843418860808E-14, as the iLogic code indicates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Somehow, the calculation the iLogic is doing goes something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Input value: exactly 440.25&lt;/P&gt;
&lt;P&gt;To database units: 440.25 * 2.54 = approx. 1118.235&lt;/P&gt;
&lt;P&gt;Output - back to working units: approx. 1118.235 / 2.54 =&amp;nbsp;440.2500000000000568434188608080&lt;/P&gt;
&lt;P&gt;Output - Input =&amp;nbsp;440.2500000000000568434188608080 - 440.25 =&amp;nbsp;&lt;SPAN&gt;5.6843418860808E-14&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another thing I don't understand, is &lt;SPAN&gt;440.2500000000000568434188608080 is WAY more than 15 decimal places of precision, so how on earth is the iLogic calculating/storing that for the value of the output anyway?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my understanding, if a calculation requires less decimal places than the working precision of the iLogic calculations (apparently 15 decimal places), then the calculations/conversion should be exact. But apparently they're not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And also in my understanding, if the difference between two numbers being compared is less than the working precision of the comparison (apparently 7 decimal places), then the comparison should say they are equal. But apparently that's wrong, too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So why are these two understandings incorrect? Why is this 5.674...E-14 value showing up in the first place, how is it even being stored in the output value, and why is such a small difference resulting in a False equality test?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Dec 2018 16:05:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8438469#M81357</guid>
      <dc:creator>DRoam</dc:creator>
      <dc:date>2018-12-01T16:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic says equal number are not equal??</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8439908#M81358</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1171223"&gt;@DRoam&lt;/a&gt;, it will work if you use the Parameter.ValueForEquals function for comparison. That gives you a DoubleForEquals object. The regular Parameter function can't do that. Here's a modified version of your original rule.&lt;/P&gt;
&lt;PRE&gt;oSetVal = 1.23456789
Parameter("d0") = oSetVal
IsEqual = If(Parameter.&lt;STRONG&gt;ValueForEquals&lt;/STRONG&gt;("d0") = oSetVal,True,False)		
MessageBox.Show( _
	"Parameter: " &amp;amp; Parameter("d0") &amp;amp; vbCrLf &amp;amp; _
	"Set value: " &amp;amp; oSetVal &amp;amp; vbCrLf &amp;amp; _
	"Equal: " &amp;amp; IsEqual )&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Dec 2018 03:07:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8439908#M81358</guid>
      <dc:creator>MjDeck</dc:creator>
      <dc:date>2018-12-03T03:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic says equal number are not equal??</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8439918#M81359</link>
      <description>&lt;P&gt;About your second question: this is an example of round-off error in double precision math. This is a limitation of double precision (15 or 16 decimal places) math in all programming languages. You can demonstrate it with JavaScript in a web browser. For instance, in Chrome hit F12 to bring up the Developer Tools. Select the Console tab in the lower pane. Then type in:&lt;/P&gt;
&lt;PRE&gt;let i=440.25
let idb=i*2.54
let idbi=idb/2.54
idbi
&lt;/PRE&gt;
&lt;P&gt;That will show the value of idbi as:&lt;BR /&gt;440.25000000000006&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Dec 2018 03:19:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8439918#M81359</guid>
      <dc:creator>MjDeck</dc:creator>
      <dc:date>2018-12-03T03:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic says equal number are not equal??</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8440904#M81360</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/537534"&gt;@MjDeck&lt;/a&gt;, thanks for the reply. That works for a parameter in the current document, but most of my rules where this is important are iterating through Parts in an assembly, so I have to access the parameters using the API. And the DoubleForEquals functionality seems to be a strictly iLogic thing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What exactly does the DoubleForEquals method do? Is is it something I could emulate after getting a parameter's value via the API, such as by rounding?&lt;/P&gt;</description>
      <pubDate>Mon, 03 Dec 2018 13:23:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8440904#M81360</guid>
      <dc:creator>DRoam</dc:creator>
      <dc:date>2018-12-03T13:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic says equal number are not equal??</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8440939#M81361</link>
      <description>&lt;P&gt;Rounding could be a viable solution, I don't know enough about double for equals to provide input on that.&amp;nbsp; Another iLogic snippet that could work is&amp;nbsp;EqualWithinTolerance(a, b, 0.001), if that works you can make the comparison without taking the extra rounding steps.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Dec 2018 13:37:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8440939#M81361</guid>
      <dc:creator>philip1009</dc:creator>
      <dc:date>2018-12-03T13:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic says equal number are not equal??</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8441026#M81362</link>
      <description>&lt;P&gt;Or if you need an API method as you're not working in iLogic then&amp;nbsp;you might have to do a precision check like the below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dim Precision As Double = 0.000001&lt;BR /&gt; If Math.Abs(Parameters("TEST1").Value&amp;nbsp;- &lt;SPAN&gt;Parameters("TEST2").Value&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;) &amp;lt; Precision Then&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MsgBox("Numbers match")&lt;/P&gt;
&lt;P&gt;Else&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;MsgBox("No match")&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;End If&lt;/P&gt;</description>
      <pubDate>Mon, 03 Dec 2018 14:13:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8441026#M81362</guid>
      <dc:creator>LukeDavenport</dc:creator>
      <dc:date>2018-12-03T14:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic says equal number are not equal??</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8441218#M81363</link>
      <description>&lt;P&gt;I'd really like to find a way to get the &lt;U&gt;actual&lt;/U&gt; model value of the parameter itself (in the parameter's units, not in database units), so that I can then use that value in any type of calculation (including a comparison) without having to worry about this "different by an amount less than 1E14" nonsense.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the rounding error always seems to be on the order of 1E14 or higher, I think rounding to 10 decimal places would be a reasonable happy medium to allow for high-precision numbers, but strip out any rounding error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried simply doing this to strip the rounding error from the retrieved parameter value:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;oParamValAPI = Round(oParam.Value/2.54,10)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used this to get oParamValAPI in my code in post #4, and it seems to work well for just about any value. The only values I could get it to throw an equality false-negative on were very large numbers (as in over a million) with lots of decimal places (more than 6).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anyone see any issue with doing this? Or know of a better way to reliably get the actual model value for use in both calculations and comparisons?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I still don't quite understand why the rounding error is happening in the first place, for such a simple low-decimal calculation like 440.25/2.54, that shouldn't require any rounding in the first place. But I'm happy to let that go if we can find a practical solution for it.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Dec 2018 15:28:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8441218#M81363</guid>
      <dc:creator>DRoam</dc:creator>
      <dc:date>2018-12-03T15:28:37Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic says equal number are not equal??</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8441257#M81364</link>
      <description>&lt;P&gt;Or would I be better off working with parameters as Decimal values, like below?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Dim oParamValAPI As Decimal = oParam.Value/2.54&lt;/PRE&gt;
&lt;P&gt;This seems to be resilient against equality false-negatives as well.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Dec 2018 15:42:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8441257#M81364</guid>
      <dc:creator>DRoam</dc:creator>
      <dc:date>2018-12-03T15:42:40Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic says equal number are not equal??</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8441696#M81365</link>
      <description>&lt;P&gt;The Decimal data type is good, but I can't guarantee that it will provide the equality test results that you expect in all cases. The question is: how accurate are the numbers that you're converting into decimals?&lt;BR /&gt;You can use the DoubleForEquals type instead of Decimal. Here's a sample:&lt;/P&gt;
&lt;PRE&gt;Dim oParamValAPI As DoubleForEquals = CDbl(oParam.Value) / 2.54&lt;/PRE&gt;
&lt;P&gt;DoubleForEquals stores the value in double precision. But it makes comparisons in single precision.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wouldn't recommend rounding, unless you're only using the rounded values for testing equality. You could easily lose more accuracy by rounding, in addition to the built-in round-off error.&lt;/P&gt;
&lt;P&gt;Instead of rounding, as&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1251402"&gt;@philip1009&lt;/a&gt;&amp;nbsp;said&amp;nbsp;you can use EqualWithinTolerance.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get the actual model value of the parameter in its own units, you can use the API method UnitsOfMeasure.ConvertUnits.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Dec 2018 18:05:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8441696#M81365</guid>
      <dc:creator>MjDeck</dc:creator>
      <dc:date>2018-12-03T18:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic says equal number are not equal??</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8441837#M81366</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;I still don't quite understand why the rounding error is happening in the first place, for such a simple low-decimal calculation like 440.25/2.54, that shouldn't require any rounding in the first place. But I'm happy to let that go if we can find a practical solution for it.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This may go way more in depth then you care to think about, but I'll put it here if you want to make your ears bleed later.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html" target="_blank"&gt;https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The long and short to your answer is that while 1118.235 is a very simple number in a base 10 (or decimal number) everything the computer does is really done in base 2 (binary)&amp;nbsp; and in base 2 that number&amp;nbsp;is much more complex.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Dec 2018 19:07:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8441837#M81366</guid>
      <dc:creator>clutsa</dc:creator>
      <dc:date>2018-12-03T19:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic says equal number are not equal??</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8441969#M81367</link>
      <description>&lt;P&gt;Just for fun, I found this site... try your numbers in this and see why they aren't perfect. (make sure to pick some of the binary options for the output)&amp;nbsp;&lt;A href="https://www.exploringbinary.com/floating-point-converter/" target="_blank"&gt;https://www.exploringbinary.com/floating-point-converter/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Dec 2018 20:00:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8441969#M81367</guid>
      <dc:creator>clutsa</dc:creator>
      <dc:date>2018-12-03T20:00:20Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic says equal number are not equal??</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8442604#M81368</link>
      <description>&lt;P&gt;This isn't an iLogic problem but as has been said, is just a fact of life when working with computers and floating point numbers.&amp;nbsp; I wrote a post several years ago about this that might help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://modthemachine.typepad.com/my_weblog/2013/08/comparing-floating-point-numbers.html" target="_blank"&gt;https://modthemachine.typepad.com/my_weblog/2013/08/comparing-floating-point-numbers.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As far as getting the "actual" value of a parameter, the true value of the parameter is stored internally in Inventor in database units.&amp;nbsp; The core of Inventor is all database units.&amp;nbsp; The only time Inventor takes units into account is when the user enters a string that can be a value with a unit or when Inventor needs to display a value.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Dec 2018 02:11:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8442604#M81368</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2018-12-04T02:11:57Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic says equal number are not equal??</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8457806#M81369</link>
      <description>&lt;P&gt;I've been having good luck so far using DoubleForEquals. However, I'm having trouble with a function I'm trying to build that can return the value of a Parameter, whether it's a numeric, text, or boolean parameter. Everything is working perfectly, except returning a DoubleForEquals value if it's numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is some sample code that demonstrates the behavior I'm seeing:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;'Before running, create a Numeric parameter called "d0"

Sub Main()
	SetValue = 440
	Parameter.Param("d0").Units = "in"
	Parameter.Param("d0").Expression = SetValue &amp;amp; " in"
	
	MessageBox.Show( _
		NumericFun &amp;amp; vbCrLf &amp;amp; TypeName(NumericFun) &amp;amp; vbCrLf &amp;amp; (NumericFun = SetValue) &amp;amp; vbCrLf &amp;amp; vbCrLf &amp;amp; _
		GenericFun &amp;amp; vbCrLf &amp;amp; TypeName(GenericFun) &amp;amp; vbCrLf &amp;amp; (GenericFun = SetValue) )
End Sub

Function NumericFun As DoubleForEquals
	Return CDbl(Parameter.Param("d0").Value / 2.54)
End Function

Function GenericFun As Object
	'If is text or Boolean param, return text or Boolean. Otherwise...
	Dim oReturnVal As DoubleForEquals = CDbl(Parameter.Param("d0").Value / 2.54)
	Return oReturnVal
End Function&lt;/PRE&gt;
&lt;P&gt;If you run the code, you'll see that even though GenericFun&amp;nbsp;&amp;nbsp;is returning a DoubleForEquals value (just like NumericFun), it's not being treated like one during the equality test.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For some reason, the function has to be explicitly defined to return a DoubleForEquals value, as NumericFun does. GenericFun clearly returns a DoubleForEquals value, as shown by the "TypeName(GenericFun)" result, but the equality test returns False anyway.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why is this? Is there anything I can do to get GenericFun to return a DoubleForEquals value that can be directly tested for equality?&lt;/P&gt;</description>
      <pubDate>Mon, 10 Dec 2018 18:44:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8457806#M81369</guid>
      <dc:creator>DRoam</dc:creator>
      <dc:date>2018-12-10T18:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic says equal number are not equal??</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8458031#M81370</link>
      <description>&lt;P&gt;the way you set "SetValue" it was an integer. I would have thought setting it to double would have worked but didn't. This seems to work though...&lt;/P&gt;
&lt;PRE&gt;Sub Main()
	Dim SetValue As DoubleForEquals = 440 '&amp;lt;-----------
	Parameter.Param("d0").Units = "in"
	Parameter.Param("d0").Expression = SetValue &amp;amp; " in"
	
	MessageBox.Show( _
		NumericFun &amp;amp; vbCrLf &amp;amp; TypeName(NumericFun) &amp;amp; vbCrLf &amp;amp; (NumericFun = SetValue) &amp;amp; vbCrLf &amp;amp; vbCrLf &amp;amp; _
		GenericFun &amp;amp; vbCrLf &amp;amp; TypeName(GenericFun) &amp;amp; vbCrLf &amp;amp; (GenericFun = SetValue) )
End Sub

Function NumericFun As DoubleForEquals
	Return CDbl(Parameter.Param("d0").Value / 2.54)
End Function

Function GenericFun As Object
	'If is text or Boolean param, return text or Boolean. Otherwise...
	Dim oReturnVal As DoubleForEquals = CDbl(Parameter.Param("d0").Value / 2.54)
	Return oReturnVal
End Function&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Dec 2018 20:00:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8458031#M81370</guid>
      <dc:creator>clutsa</dc:creator>
      <dc:date>2018-12-10T20:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic says equal number are not equal??</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8458315#M81371</link>
      <description>&lt;P&gt;In my real-life use of the function, I won't be initially setting the value via code at all.&amp;nbsp;This is a more true-to-life way to test the function how I'll actually be using it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;'Before running, create a Numeric parameter called "d0" and set to 440 inches.

Sub Main()
	MessageBox.Show( _
		NumericFun &amp;amp; vbCrLf &amp;amp; TypeName(NumericFun) &amp;amp; vbCrLf &amp;amp; (NumericFun = 440) &amp;amp; vbCrLf &amp;amp; vbCrLf &amp;amp; _
		GenericFun &amp;amp; vbCrLf &amp;amp; TypeName(GenericFun) &amp;amp; vbCrLf &amp;amp; (GenericFun = 440) )
End Sub

Function NumericFun As DoubleForEquals
	Return CDbl(Parameter.Param("d0").Value / 2.54)
End Function

Function GenericFun As Object
	'If is text or Boolean param, return text or Boolean. Otherwise...
	Dim oReturnVal As DoubleForEquals = CDbl(Parameter.Param("d0").Value / 2.54)
	Return oReturnVal
End Function&lt;/PRE&gt;
&lt;P&gt;So the DoubleForEquals "magic" needs to take place on the value returned by GenericFun itself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To give a bit more explanation of what I'm after, I basically have two use cases for the GenericFun function:&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Use Case 1:&lt;/U&gt;&amp;nbsp;To get the value of a numeric Parameter (the real-life version of the function can take a parameter name as an argument, but this sample GenericFun function just gets the "d0" parameter to keep it simple) and assign it to a variable for use in both calculations and equality testing. I can use DoubleForEquals for this, e.g.:&lt;/P&gt;
&lt;PRE&gt;Dim oValue As DoubleForEquals = GenericFun

If oValue = 440 Then
	Parameter("x") = oValue * 3.25
Else
	Parameter("x") = oValue * 4
End If&lt;/PRE&gt;
&lt;P&gt;&lt;U&gt;Use Case 2:&lt;/U&gt;&amp;nbsp;For immediate equality testing, without first being assigned to a variable. Needs to return a value that can be equality-tested directly, e.g.:&lt;/P&gt;
&lt;PRE&gt;If GenericFun = 440 Then
	Parameter("x") = 1430
End If&lt;/PRE&gt;
&lt;P&gt;My goal is to be able to use the same function for both use cases, without having to do anything special. GenericFun accomplishes Use Case #1 just fine. However, I can only get it to accomplish #2 if it's explicitly defined to return a DoubleForEquals value, like NumericFun. But then I would have to create and use a separate function for getting text parameter values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Aside from being used directly in equality tests, my real-life GenericFun does everything perfectly: getting text, boolean, and numeric parameter values, converting numeric parameters to desired output units, and equality tests after assigning the returned value to a DoubleForEquals variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there's some way to get GenericFun to spit out a DoubleForEquals value that's actually treated as such by the equality test, then I'll have a function that's the equivalent of the Parameter.Value method, except:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;It actually returns the value in the parameter's units, rather than database units&lt;/LI&gt;
&lt;LI&gt;It can return Nothing, 0, empty string, or False (depending on expected type) if the parameter doesn't exist, rather than throwing an exception&lt;/LI&gt;
&lt;LI&gt;The result can be used directly in equality comparisons&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Dec 2018 21:40:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8458315#M81371</guid>
      <dc:creator>DRoam</dc:creator>
      <dc:date>2018-12-10T21:40:31Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic says equal number are not equal??</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8458340#M81372</link>
      <description>&lt;P&gt;It also appears that only the number you're checking against has to be set as the DoubleForEquals...&lt;/P&gt;
&lt;PRE&gt;Sub Main()
	
	Dim SetValue As DoubleForEquals = 440 '&amp;lt;-----------
	Parameter.Param("d0").Units = "in"
	Parameter("d0") = SetValue
	'Parameter.Param("d0").Expression = SetValue &amp;amp; " in"
	
	MessageBox.Show( _
		SetValue &amp;amp; vbCrLf &amp;amp; TypeName(SetValue) &amp;amp; vbCrLf &amp;amp; vbCrLf &amp;amp; _
		NumericFun &amp;amp; vbCrLf &amp;amp; TypeName(NumericFun) &amp;amp; vbCrLf &amp;amp; (NumericFun = SetValue) &amp;amp; vbCrLf &amp;amp; vbCrLf &amp;amp; _
		GenericFun &amp;amp; vbCrLf &amp;amp; TypeName(GenericFun) &amp;amp; vbCrLf &amp;amp; (GenericFun = SetValue))
End Sub

Function NumericFun As Double
	Return CDbl(Parameter.ValueForEquals("d0"))
End Function

Function GenericFun As Object
	'If is text or Boolean param, return text or Boolean. Otherwise...
	Dim oReturnVal = CDbl(Parameter.ValueForEquals("d0"))
	Return oReturnVal
End Function
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Edit: I hadn't seen your last post when I posted this. I was just posting something I had found.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Dec 2018 21:56:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-says-equal-number-are-not-equal/m-p/8458340#M81372</guid>
      <dc:creator>clutsa</dc:creator>
      <dc:date>2018-12-10T21:56:51Z</dc:date>
    </item>
  </channel>
</rss>

