Robust Geometry - Grasshopper2024-03-28T20:51:44Zhttps://www.grasshopper3d.com/forum/topics/robust-geometry?commentId=2985220%3AComment%3A1560890&x=1&feed=yes&xn_auth=noIt's not simple arithmetic. Y…tag:www.grasshopper3d.com,2016-07-06:2985220:Comment:15608902016-07-06T13:43:34.977ZArendhttps://www.grasshopper3d.com/profile/Arend
<p>It's not simple arithmetic. You found out limitations of floating points numbers.</p>
<p>Aside from that your testcase is comparing two floating point numbers without a "epsilon" value (some would argue this to be mortal sin). There are much more cases where two floating points will not be exactly the same.</p>
<p>You correctly point out that there's a limitation around 15 to 17 digits. (s/r are about this size). In proportion the error between the two numbers is about 2.67E-16.</p>
<p>Not…</p>
<p>It's not simple arithmetic. You found out limitations of floating points numbers.</p>
<p>Aside from that your testcase is comparing two floating point numbers without a "epsilon" value (some would argue this to be mortal sin). There are much more cases where two floating points will not be exactly the same.</p>
<p>You correctly point out that there's a limitation around 15 to 17 digits. (s/r are about this size). In proportion the error between the two numbers is about 2.67E-16.</p>
<p>Not sure what you're trying to accomplish with the ExactArithmatic / ExactNumber? But if you change the type from double to decimal in C#, this testcase will succeed.</p>
<blockquote><p>decimal a = 12312.23223213M;<br/>decimal b = 12455343.123187843M;<br/>decimal r = (a + b + b) * a * b;<br/>decimal s = (a * a * b + b * a * b + b * a * b);<br/>decimal e = r - s;</p>
<p>// e = 0</p>
<p></p>
</blockquote>
<p><strong>.NET floating point numbers:</strong></p>
<p><a rel="nofollow" href="https://msdn.microsoft.com/en-us/library/9ahet949.aspx" target="_blank">https://msdn.microsoft.com/en-us/library/9ahet949.aspx</a>|</p>
<p><strong>Floating point guide:</strong> <a rel="nofollow" href="http://floating-point-gui.de/" target="_blank">http://floating-point-gui.de/</a></p>
<p>This is also why you never should compare floating point numbers to check if they're exact, but if they're close enough. </p>
<p>I still have no clue where you would want to be going from here? What problem are you trying to solve?</p> Hey Tom,Good questions!Indepe…tag:www.grasshopper3d.com,2016-06-24:2985220:Comment:15551402016-06-24T19:06:20.765ZOrtler Markhttps://www.grasshopper3d.com/profile/OrtlerMark
<p style="text-align: left;">Hey Tom,<br></br><br></br>Good questions!<br></br>Independence is the major reason, but also exactness...<br></br><br></br></p>
<p>A simple TestCase which fails hard:</p>
<p>(sure, this isn't a real-world example, its just simple arithmetic. But I guess important to be correct/robust)<br></br><br></br></p>
<p>[TestMethod]<br></br> public void SimpleArithmetic()<br></br> {<br></br> double a = 12312.23223213;<br></br> double b = 12455343.123187843;</p>
<p> var xa = new ExactNummeric(a);<br></br> var…</p>
<p style="text-align: left;">Hey Tom,<br/><br/>Good questions!<br/>Independence is the major reason, but also exactness...<br/><br/></p>
<p>A simple TestCase which fails hard:</p>
<p>(sure, this isn't a real-world example, its just simple arithmetic. But I guess important to be correct/robust)<br/><br/></p>
<p>[TestMethod]<br/> public void SimpleArithmetic()<br/> {<br/> double a = 12312.23223213;<br/> double b = 12455343.123187843;</p>
<p> var xa = new ExactNummeric(a);<br/> var xb = new ExactNummeric(b);</p>
<p> ExactNummeric xr = (xa + xb + xb) * xa * xb;<br/> ExactNummeric xrs = (xa * xa * xb + xb * xa * xb + xb * xa * xb);<br/> ExactNummeric xre = xr - xrs;</p>
<p> double r = (a + b + b) * a * b;<br/> double s = (a * a * b + b * a * b + b * a * b);<br/> double e = r - s;</p>
<p> double xrd = xre;</p>
<p> Assert.AreEqual(0d, xrd);<br/> Assert.AreNotEqual(0d, e);<br/> }</p>
<p></p>
<p><strong>The second Assert:</strong></p>
<p>Expected = 0<br/>Actual = 1024 (variable 'e')<br/><br/><span style="text-decoration: underline;">(For testing, there are .cs files attached)</span><br/><br/><br/></p>
<p><strong><span>gaußian solver</span><br/></strong>I'm going to have a look at this. thanks to point this out. I had a quick look; looks promising. But I have to have a deeper look... In the meantime, thanks...<br/><br/><br/></p>