Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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
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!
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
Hi
James Summerson and Jonathan Penuliar i need explanation for it.
Thanks.
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
I have edited my reply to suit, johnDawson
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