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

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.

From "http://en.wikipedia.org/wiki/Modulo_operation"

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.