iLogic says equal number are not equal??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I often have iLogic rules check if a parameter equals a value, in order to take some appropriate action. 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. I've run into this strange glitch multiple times before, and thought I'd post to try and find out what the heck is going on.
I put together a quick script to demonstrate the issue. 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:
oSetVal = 1.23456789 Parameter("d0") = oSetVal IsEqual = If(Parameter("d0") = oSetVal,True,False) MessageBox.Show( _ "Parameter: " & Parameter("d0") & vbCrLf & _ "Set value: " & oSetVal & vbCrLf & _ "Equal: " & IsEqual )
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.
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).
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?
Running Inventor 2017.4.6 on a Lenovo Windows 10 64-bit desktop