Jump to content
Macro Express Forums

Modulo Operation For Macex

Recommended Posts

I needed a quick-and-dirty Modulo calculation so I just wrote this from scratch. Here's my macro which works as a basic calculator.


Modulo operation as defined in Wikipedia

In computing, the modulo operation finds the remainder of division of 
one number by another.

Given two numbers, a and n, a modulo n (abbreviated as a mod n) is 
the remainder, on division of a by n.

To calculate:

a mod n

a - n (floor( a / n ))


This macro has only been lightly tested, but it appears to work for me. The macro returns the same results as the Modulo function in Win XP's Calculator (Scientific view).


Of course, you can also get a Modulo (Mod) function from PG Macros:




But I didn't want to install PG Macros just for one function.


Link to comment
Share on other sites

Perfect! The one in our PGM Functions Library uses Decimals %Dxx% and extra step to extract just the whole number. The { Math - Mod } function was created before Macro Express had the ability to mix Integers and Decimals in a single calculation.


Speaking of fun things, the { Math - Square Root } function was done with native Macro Express code using a "divide and average" method ... it must have been a day when I had a lot of time on my hands ;)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...