Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How this function works?

Hi All,

Can any one please let me know how it is possible, and what it the logic in it?

mod( -4,3 ) returns 2

Thanks

John

1 Solution

Accepted Solutions
swuehl
MVP
MVP

I think it's working like the Excel function, and this function can be (according to Excel Help) evaluated like:

MOD(n, d) = n - d*INT(n/d)


So:

mod(-4,3) = -4 - 3*(-2) = +2




View solution in original post

6 Replies
ThornOfCrowns
Specialist II
Specialist II

mod(x1 , x2)
Mathematical modula function. Both parameters must have integer values. x2 must be greater than 0. The result is the non-negative remainder of an integer division.

The mod function is defined as the amount by which a number exceeds the largest integer multiple of the divisor that is not greater than that number. In the case of mod(-4,3), the largest number would be -6 and the difference between -6 and -4 is 2.

Very fruity, but that's what you get playing about with negative numbers!

jpenuliar
Partner - Specialist III
Partner - Specialist III

From Qlikview HelpF1)


mod(x1 , x2)

Mathematical modula function. Both parameters must have integer values. x2 must be greater than 0. The result is the non-negative remainder of an integer division.

Examples:

mod( 7,2 ) returns 1

mod( 7.5,2 ) returns NULL

mod( 9,3 ) returns 0

mod( -4,3 ) returns 2

mod( 4,-3 ) returns NULL

mod( -4,-3 ) returns NULL

Not applicable
Author

Hi

James Summerson and Jonathan Penuliar  i need explanation for it.

Thanks.

swuehl
MVP
MVP

I think it's working like the Excel function, and this function can be (according to Excel Help) evaluated like:

MOD(n, d) = n - d*INT(n/d)


So:

mod(-4,3) = -4 - 3*(-2) = +2




ThornOfCrowns
Specialist II
Specialist II

I have edited my reply to suit, johnDawson

jaimeaguilar
Partner - Specialist II
Partner - Specialist II

Hi,

the mod examples with positive integers are quite easy to understand. However, the negative integers divisions could be kind of confusing. In the specific example mod(-4,3) = 2, the explanation is that -4 / 3 = -1.3333. So the  Module is the remainder. With positive numbers is quite easy to understand that 4 - 3 equals 1.

But with negative the remainder would be calculated as --> -6 - (-4) = 2.

The explanation is that with negative numbers -3 is not less than -4, so you'll need to look at -6 (-4 * 2 = -6 would be the next possible option for this division).

hope this helps,

regards