Cos 90 degree (1.5708 radian) = 6.123233 ??

EL's Avatar

EL

11 Mar, 2020 02:37 PM

Hello! cos 90 degree should be 0, isn't it?
The screencap and nodebox file is attached for reference.
Thanks!

  1. 1 Posted by EL on 11 Mar, 2020 02:39 PM

    EL's Avatar

    Attached nodebox source file for your test.

  2. 2 Posted by EL on 11 Mar, 2020 03:01 PM

    EL's Avatar

    Oh, my bad, 6.123233... E-17 == 0.00000000000000006123233... which is basically 0
    Please close the topic.

  3. Support Staff 3 Posted by john on 11 Mar, 2020 06:48 PM

    john's Avatar

    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

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Already uploaded files

  • Screenshot_2020-03-11_at_10.19.41_PM.png 574 KB

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

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

Recent Discussions

24 Jan, 2025 07:50 AM
22 Jan, 2025 11:42 PM
21 Jan, 2025 09:43 AM
21 Jan, 2025 09:41 AM
21 Jan, 2025 09:36 AM

 

21 Jan, 2025 02:00 AM
16 Jan, 2025 08:30 PM
15 Jan, 2025 06:37 AM
04 Jan, 2025 04:09 AM
03 Jan, 2025 05:32 PM
29 Dec, 2024 12:06 PM