tag:support.nodebox.net,2012-11-01:/discussions/nodebox-2-3/6204-cos-90-degree-15708-radian-6123233NodeBox: Discussion 2020-03-11T18:50:17Ztag:support.nodebox.net,2012-11-01:Comment/481504752020-03-11T14:39:29Z2020-03-11T14:39:30ZCos 90 degree (1.5708 radian) = 6.123233 ??<div><p>Attached nodebox source file for your test.</p></div>ELtag:support.nodebox.net,2012-11-01:Comment/481504752020-03-11T15:01:57Z2020-03-11T15:01:57ZCos 90 degree (1.5708 radian) = 6.123233 ??<div><p>Oh, my bad, 6.123233... E-17 == 0.00000000000000006123233... which is basically 0<br>
Please close the topic.</p></div>ELtag:support.nodebox.net,2012-11-01:Comment/481504752020-03-11T18:48:23Z2020-03-11T18:50:17ZCos 90 degree (1.5708 radian) = 6.123233 ??<div><p>El,</p>
<p>I'm glad you shared this. I have hit this exact issue before and it was bewildering until I figured it out.</p>
<p>The problem is numerical precision - a problem common to all languages and computers in general - not just NodeBox. It pops up all the time in places you wouldn't expect. And it can play havoc with your code!</p>
<p>As you said, "6.123233... E-17" is basically 0. But it's not EXACTLY zero. So if you are relying on a compare node to test whether this value is zero, compare will return a false. After that, bad things may happen.</p>
<p>I have a fix for this.</p>
<p>The next release of my node library includes a new node (actually a subnetwork) called precision. I am attaching it here in a demo file (see screenshot).</p>
<p>Precision is very simple. It returns an altered version of any number you pass to it, trimmed to as many digits as you wish. If you specify a zero, it will return an integer (using the round node); otherwise it will return a float.</p>
<p>Note that it is not just changing the format. It is changing the actual value of the number.</p>
<p>Whenever I am doing calculations that can produce infinitesimal values (like cos), I routinely pass the results through this precision node before doing any divisions or compares. You can set the precision of cos(90 degrees) to anything up to 15 digits to make sure values like this will be true zeroes, not "almost zeroes". In practice, 4 or 5 digits is good enough for most calculations.</p>
<p>Hope that helps!</p>
<p>John</p></div>john