12-04-2022, 01:53 AM
(12-04-2022, 01:38 AM)bplus Wrote: Yes, it could go either way I suppose. I see real use from me with keeping the return between 0 and denominator.
I've read it depends on the language how the results are represented. So without any reliable consistency, and a few different definitions, I'm in your boat. Use what is beneficial. To me a number MOD 5 should make a nice 1,2,3,4,5 pattern for file record recognition. In the second loop that is accomplished by setting the patented pattern variable to 1.
Code: (Select All)
$CONSOLE:ONLY
x = -5
pattern = 0
FOR y = -9 TO 10
PRINT y; MODn(y, x, pattern)
NEXT
PRINT "==================="
pattern = 1
FOR y = -9 TO 10
PRINT y; MODn(y, x, pattern)
NEXT
FUNCTION MODn (y, x, pattern)
MODn = y - ABS(x) * INT(y / ABS(x)) + pattern * ABS(x) * (1 - ABS(SGN(y MOD x)))
END FUNCTION
Pete