4 Replies Latest reply on Jul 3, 2013 6:04 AM by hugall1998

# The MOD function in Filemaker (11) - inconsistency?

Hi all,

I needed to use the MOD function in my current solution so I decided to freshen my memory and looked it up in the HELP in FM 11 (windows).

The definition is clear [ Mod ( number; divisor) ] and the examples understandable until I encountered the following:

Mod( 7;-5) returns -3 (note, the divisor is minus 5)

In my mind, the return (the remainder) ought to be 2, not - 3 (minus 3), see the table below, row 11.

I searched for answers on the FM forum but found nothing applicable and after searching and some reading on the wide web the following assumptions emerged:

... The outcome (DIVISOR times multiplier) must be the closest value below the NUMBER

... The multiplier must be an integer (whole number) and can be 0 (zero)

... In case of a negative sign, a -30 is lower than -20

Also, there seem to be different definitions around, Java, C++ and other various programming languages are not always in agreement.

Excel (2010, win) gives the same results and Filemaker 11 (win).

I made the following table, using the examples in the Filemaker HELP (for win, vers. 11), please take a look at the rows 10 and 11, and 14 and 15. I find the remainder in rows 11 and 15 respectively, more logical than the answers that both Filemaker and Excel (see the column to the right) give as the correct ones (rows 10 and 14).

In the right lower corner I included in a small table the results from Filemaker (I set up the fields with the mod function, giving the remainder. The "multiplier" to the right of the remainder uses the DIV function, I display it to compare with the multiplier in the excel table above).

I guess it is a sacrilege to doubt the almightly Filemaker (:-) but is the example in the HELP file correct? Math is not my strongest point, especially with negative numbers and as result I'm missing something vital, so I appreciate a hard look from your experienced eyes. If the definition and/or assumptions above are incorrect I'd be grateful for corrections.

many thanks

Larus Jon

• ###### 1. Re: The MOD function in Filemaker (11) - inconsistency?

Larus Jon,

How many -5 values are there in +7?

Test for ending sequence is:     <= 0 or remainder is less than divisor.

1st pass at -5:          7 - 5 = 2, fails both tests so we are not done yet.

2nd pass at -10:     7 - 10 = -3, <= 0 so we are done.

Using the Mod () function may not be what you want. But, this is expected behavior.

In some compilers, the modulo operation is implemented as mod(a, n) = a - n * floor(a / n). For example, mod(7, 3) = 7 - 3 * floor(7 / 3) = 7 - 3 * floor(2.33) = 7 - 3 * 2 = 7 - 6 = 1.

1 of 1 people found this helpful
• ###### 2. Re: The MOD function in Filemaker (11) - inconsistency?

just curious ...

why is your divisor minus 5 ? what are you counting ?

greg

> the divisor is minus 5

• ###### 3. Re: The MOD function in Filemaker (11) - inconsistency?

ch0c0halic,

many thanks for this, setup the way you do makes it more transparent although I'm not sure I fully understand it. This is however more of an academic exercise than a practical problem as I don't foresee using a divisor with a minus sign in any real life solution of mine.

I trust your verdict that this is expected behaviour and will proceed to use the MOD function.

Again, many thanks.

Lárus Jón.

• ###### 4. Re: The MOD function in Filemaker (11) - inconsistency?

Hi gdurniak,

Actually, I'm not using a divisor with a minus sign, my post was more a call for a practical explanation of what I found/thought inconsistent in the example on the filemaker Help page.  As ch0c0halic (see his reply to my post) explained, all is in order and there are no inconsistencies, the MOD behaviour is as expected.   As it turned out, I simply didn't fully understand the workings of the MOD function