Cos 90 degree (1.5708 radian) = 6.123233 ??
Hello! cos 90 degree should be 0, isn't it?
The screencap and nodebox file is attached for reference.
Thanks!
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by EL on 11 Mar, 2020 02:39 PM
Attached nodebox source file for your test.
2 Posted by EL on 11 Mar, 2020 03:01 PM
Oh, my bad, 6.123233... E-17 == 0.00000000000000006123233... which is basically 0
Please close the topic.
Support Staff 3 Posted by john on 11 Mar, 2020 06:48 PM
El,
I'm glad you shared this. I have hit this exact issue before and it was bewildering until I figured it out.
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!
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.
I have a fix for this.
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).
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.
Note that it is not just changing the format. It is changing the actual value of the number.
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.
Hope that helps!
John