Well Steve posted while I was about to...
Testing Pete's in a very common situation for us hobbyists:
This is actual situation that comes up and you wish there was a better way.
Steve's thing should work fine for this but Pete takes on Negative Modulus! What a guy!
Negative Modulus sounds to me like a psychologist looking for business.
OK Pete does this hold pattern for a Modulus of a negative _Float?
2 points for anyone who can come up with some example where a modulus of negative float would be needed.
I confess I am still getting over doing negative integers with MOD let alone floats positive or negative!
Testing Pete's in a very common situation for us hobbyists:
Code: (Select All)
_Title "MOD versus modx test Petes new thing ;-))" ' b+ 2022-11-28
Screen _NewImage(800, 600, 32)
x = 300: y = 300: dx = -5
Do
Cls
Print "spacebar to exit this first screen, I want circle to exit stage left and enter stage right..."
Circle (x, y), 20
x = (x + dx) Mod _Width ' head left loop around and head left???
_Display 'no blinking
_Limit 10 ' 10 xs per sec
Loop Until _KeyDown(32)
Cls
Locate 15, 20: Print "That sucks, I am talking about normal MOD for negative numbers."
Print
Locate 17, 20: Print " OK try Pete's new and improved super dupper modx(), zzz..."
_Display
Sleep
_KeyClear
Cls
x = 300: y = 300: dx = -5
Do
Cls
Print "escape to quit, circle should leave screen on left and return on right"
Circle (x, y), 20
x = modx(x + dx, _Width) ' head left loop around and head left???
If x > 400 Then
Locate 30, 30: Print "It works! It works! Holy crap it works!"
End If
_Display 'no blinking
_Limit 10 ' 10 xs per sec
Loop Until _KeyDown(27)
Function modx (i, j)
modx = (Abs(i) - Abs(j) * ((Abs(i) \ Abs(j)) + (1 - Sgn(i)) \ 2)) * Sgn(i Mod j)
End Function
This is actual situation that comes up and you wish there was a better way.
Steve's thing should work fine for this but Pete takes on Negative Modulus! What a guy!
Negative Modulus sounds to me like a psychologist looking for business.
OK Pete does this hold pattern for a Modulus of a negative _Float?
2 points for anyone who can come up with some example where a modulus of negative float would be needed.
I confess I am still getting over doing negative integers with MOD let alone floats positive or negative!
b = b + ...