Modulo III


Euclidean Modulo

Divides a dividend by a divisor and returns two outputs: the remainder (always non-negative) and the quotient (the number of whole times the divisor fits into the dividend, floored toward negative infinity).

Inputs

  • Input 1: Dividend (the number being divided)
  • Input 2: Divisor (the number to divide by)

Outputs

  • Output 1: Quotient (floor of dividend ÷ divisor)
  • Output 2: Remainder (always in the range 0 to divisor-1)

How it works internally

The core is a truncating division: dividend × (1/divisor), then floor via subtracting the fractional part. This gives a truncation remainder (dividend - quotient × divisor), which can be negative when the dividend is negative.

The Euclidean correction negates the truncation remainder and feeds it through GreaterThanZero. If the remainder was negative, the negated value is positive, GreaterThanZero outputs 1, and the divisor is added back to bring the remainder into the non-negative range. If the remainder was zero or positive, nothing happens.

Usage examples

Scale degree wrapping: with divisor 7, an input of 15 returns quotient 2 (octave) and remainder 1 (scale degree). An input of -1 returns quotient -1 and remainder 6 (wraps around rather than going negative).

Phase wrapping, buffer looping, or any situation where you need a value to stay within a fixed non-negative range regardless of the sign of the input.

Note: divisor must be non-zero. A divisor of zero will cause a division-by-zero through the OnePerX node.

Preview


Install

  • Copy
  • Open
  • Download
Copy

1 - Click the Copy to Clipboard button:

2 - Open the AudioNodes webapp or desktop app (if not already open)

3 - In AudioNodes, either press Ctrl+V (Cmd+V on Mac), or right click on empty Patcher area to open the Node browser, then click the Paste button at the bottom

Open

Click the Open in Webapp Directly button, which will automatically open this snippet in the AudioNodes webapp:

Note: this will open a new AudioNodes instance. If you already have another one open, quicksaving might clash between them, so it's best to close the already running instance first.

Download

Click the Download Project File button to generate a project file you can open:

Then, from inside AudioNodes, you can open this snippet just like any other project.


Author

an anonymous user


Total Nodes

29 Nodes