>The mod command gives stange results when done this way:
>Mod(-13,4). I would expect this to return either 1 or -1 but it returns 3.
>Visual Basic return -1 for this command but Ruby return the same thing as VFP. Can someone explain this to me.... Thanks.
You can visualize this as follows. (Instead of mod(13, 4), I will write 13 % 4, which is also valid in VFP.)
To calculate 13 % 4, 4 is repeatedly subtracted, until you get a result such that 0 < = x < 4.
To calculate -13 % 4, 4 is repeatedly added, until (once again) you get a result such that 0 < = x < 4.
Of course, VFP will optimize this - it will not subtract or add the same number millions of times.
Also, note that you can use the modulus with non-integers. For example, you can normalize an angle (in radians) to the range 0 - 2pi:
? angle_in_radias % (2 * pi())
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)