12-31-2022, 04:25 PM
(12-31-2022, 04:39 AM)PhilOfPerth Wrote:(12-03-2022, 05:22 PM)bplus Wrote: Break this?I didn't see Chia Pet's post, but toggle = 1 - toggle always gives result=toggle; to toggle between 1 and 0 shouldn't it be toggle = Abs(toggle - 1) ?
For ideal modulus, I imagine it should be between 0 and the divisor = modulus whether divisor is pos or negative.
I read johannhowitzer Wrapping, capping and other... and it all fell in place what we are trying to reach, keeping numbers between 0 and the divisor whether integer or float like Pi, we just want a proper remainder.
Code: (Select All)_Title "Remainder test" ' b+ for a modulus that always returns a number between 0 and divisor
' if divisor is negative then return a rational between 0 and some rational d < 0
' if divisor is positive then return a rational between 0 and some rational d > 0
' if divisor is 0 ? can't divide by 0
' Do we need to round? Doesn't look like it but I just ran a couple quick tests. Folks here can find fault with anything! ;-))
' NOTE: when testing don't leave space between , and d eg, do 5,3 not 5, 3
$Console:Only
Do
Input "0's quit, please enter n, d to find remainder n/d between 0 and d "; n, d
If (n = 0) Or (d = 0) Then End
Print Remainder##(n, d)
Loop
' modeled on MODn
'ref Pete https://qb64phoenix.com/forum/showthread.php?tid=1195&pid=10983#pid10983
Function Remainder## (n##, d##)
If d## = 0 Then Exit Function
Remainder## = n## - (d##) * Int(n## / (d##))
End Function
BTW best toggle I've seen and used often from Chia Pet:
toggle = 1 - toggle
You might be assuming toggle takes on -1 value like QB64's True value, no. Toggle is only ever 0 or 1 specially if DIM's as an integer as opposed a float.
b = b + ...