11-05-2009 09:06 AM - edited 11-05-2009 09:07 AM
Today we have the versatile function "Quotient & Remainder". This guy finds its way into many a for loop or while loop when you want to repeat a set of indices (say 0,1,2,0,1,2...). Or, let's say you need to know the fractional part of a number, just divide by 1 and take the remainder, plus you get the integer part as well. Finally, it's simple to check if a number is even and to pad it to the next even number if necessary. I am sure there are a few more clever uses.
VIOTD groundrules here.
11-05-2009 09:09 AM
The use of Quotient & Remainder with floats has been brought up before for those who intend to delve into that deep pool.
Example: http://forums.ni.com/ni/board/message?board.id=170&thread.id=163975
11-05-2009 09:11 AM
If you want to perform an action every n-th time a loop iterates, do wire the i terminal to the Q&R and the remainder to a case structure selector term. Use case 0 for the action.
Felix
11-05-2009 09:58 AM - edited 11-05-2009 10:00 AM
Another typical use is an integer division where we need to increment by one in order not to lose the data in the remainder if there is one (e.g. when reshaping a1D array to a 2D array and the last row will be only partially filled.)
I usually use the following construct.
11-05-2009 10:56 AM - edited 11-05-2009 11:06 AM
I think the first time I really used the modulo function (as it is called in other languages), I used it to alternate the background color of rows of a table from a database query. /sigh at NI for not letting me alternate the background color of a table, or an array.
The text "modulo" in the Search Palettes feature, should point to the Quotient & Remainder function, but alas, it doesn't.
You gotta appreciate the fact that there is an actual function to the remainder of an integer based division operation in programming. I remember learning about it in elementary and then it was never mentioned again until college.
Edit: Spelling. I wish my web browser's spellcheck function worked on the NI forum ><.
11-06-2009 09:18 AM