Divide Safely

john's Avatar

john

12 Mar, 2024 04:58 AM

Attached is a simple but handy new node: divide_safe.

Divide_safe allows you to perform divisions without having to check for division by zero errors. Just feed in a numerator and denominator. If the denominator is OK it will just perform a normal division. But if the denominator is zero or negative zero it will instead return a specified replacement value. All the checking is done for you.

The demo shows a graph of y = 1/x. Using a normal divide node would trigger an error when x = 0. Using divide_safe instead allows you to draw the graph with no extra fussing.

In this case I used 0 as the replacement value, If you increase or decrease that value you will see the red dot move up and down. The value you select in other scenarios will depend on your situation.

This node is not rocket science, but it's a real time-saver. Enjoy!

  1. 1 Posted by florisdejonge on 14 Mar, 2024 06:08 PM

    florisdejonge's Avatar

    Great node John. I get the can't divide by 0 a lot when using the mask node. Is this node also a solution for that?

  2. Support Staff 2 Posted by john on 14 Mar, 2024 07:23 PM

    john's Avatar

    Floris,

    You mean you get divide by 0 errors when you render the latest 3.1 version of my mask node? That shouldn't ever happen.

    Could you please send me a Nodebox file which triggers this error so I can track it down? If I can find the offending divide node I will replace it with my divide_true node and update the mask node.

    Thanks!

    John

  3. 3 Posted by florisdejonge on 14 Mar, 2024 07:38 PM

    florisdejonge's Avatar

    Thanks for the quick response. Maybe I opened a file with an old mask node, or I've integrated an old version in one of my own subnetworks that I use a lot. I will post it as soon as I encounter the error.

Reply to this discussion

Internal reply

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

Attaching KB article:

»

Already uploaded files

  • divide_safe_screenshot.png 454 KB
  • divide_safe_demo.ndbx.zip 1.79 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

23 Apr, 2024 07:54 PM
19 Apr, 2024 04:41 AM
16 Apr, 2024 06:18 PM
16 Apr, 2024 04:23 AM
08 Apr, 2024 01:28 AM

 

07 Apr, 2024 11:50 PM
05 Apr, 2024 11:47 PM
05 Apr, 2024 12:30 AM
25 Mar, 2024 08:48 PM
14 Mar, 2024 07:40 PM
14 Mar, 2024 07:38 PM