Divide Safely

john's Avatar


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


    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.



  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


? 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

17 Jun, 2024 02:26 PM
15 Jun, 2024 01:44 PM
08 Jun, 2024 09:05 AM
08 Jun, 2024 09:00 AM
04 Jun, 2024 04:37 AM