Divide Safely
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!
- divide_safe_screenshot.png 454 KB
- divide_safe_demo.ndbx.zip 1.79 KB
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 florisdejonge on 14 Mar, 2024 06:08 PM
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?
Support Staff 2 Posted by john on 14 Mar, 2024 07:23 PM
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 Posted by florisdejonge on 14 Mar, 2024 07:38 PM
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.