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:

http://www.pgmacros.com/math_and_science.htm

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

Modulo_calc.mex

##### 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

##### Share on other sites

Heh, "divide and average" aka the Babylonian method. Seems tedious, but doable. Hopefully, I won't need to do square root calculations anytime soon.

Note to other users - PG Macros is the easier route.

##### Share on other sites

I'm sure the Babylonians had a lot of time on their hands, except for that tower thing. But really, what was else was there to do except Macro Express coding on a hot Saturday night in the desert?

##### Share on other sites

Sorry to have to correct Joe on this, but I feel sure it was a Sunday! And it wasn't that hot!

## Join the conversation

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

×
×