This content has been marked as final. Show 2 replies
The % character used for modulo in many areas of SVRF doesn't seem to be supported for builtin languages within SVRF such as device property computation. I'm not aware of a workaround.
Modulo is based upon the Euclidean division algorithm, which is this. For integers a, d, q, and r:a = qd + rhere q is the quotient, d is the divisor, and r is the remainder. Note that d (the modulus) is not 0.Based upon the Euclidean definition of division, the remainder must always be non-negative, and this can be guaranteed. Here are some examples:7 = 2(3) + 17 = -2(-3) + 1-7 = -3(3) + 2-7 = 3(-3) + 2If we isolate the remainder, we have this:r = a - qdBut this is not how Donald Knuth decided to define % in C. He defined it this way:r = a - (floor(a/d))dor just commuting the final 2 termsr = a - d(floor(a/d))where floor( ) means truncation toward the negative direction. Using our cases above, we have this:r = 7 - 3(floor(7/3)) = 7 - 3(2) = 1r = 7 - (-3(floor(7/-3)) = 7 - (-3(-3)) = -2r = -7 - 3(floor(-7/3)) = -7 - 3(-3) = 2r = -7 - (-3(floor(-7/-3)) = -7 - (-3(2)) = -1This definition can be more useful in computational situations than the number-theoretical definition. Note that the sign of the remainder is the same as the sign of the divisor in this scheme.Assuming that you want the C implementation (%) and not the number-theoretical version, you might be able to implement the following in the device property computation. In the built-in languages, we have the trunc( ) function, which truncates toward 0 (instead of toward the negative direction).# a is your dividend, d is your divisor, r is your remainder# the program will need to guarantee d != 0if (a/d) >= 0r = a - d*(trunc(a/d))else# trunc rounds toward 0. for a/d < 0, this means we need to subtract 1 from trunc(a/d)r = a - d*(trunc(a/d)-1)using our examples above:r = 7 - 3(trunc(7/3)) = 7 - 3(2) = 1r = 7 - (-3(trunc(7/-3)-1)) = 7 - (-3(-2-1)) = 7 - (-3(-3)) = -2r = -7 - 3(trunc(-7/3)-1)) = -7 - 3(-2-1)) = -7 - 3(-3) = 2r = -7 - (-3(trunc(-7/-3)) = -7 - (-3(2)) = -1So that might be a worthwhile solution.