Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Mod Operator (-3 Mod 64 = -3?!) Help! :]

Hello HF! :D

I hope one of you can help me with this annoying problem!

If you perform: -3 Mod 64 the actual answer is: 61

However, in my vb code, it remains: -3

Code:

msgbox( -3 Mod 64 )

Am I some how doing something wrong, hope you guys can help me! Thank you! :D
.-=~
64 - 3 ?

Don't get what you have an issue with

please explain more
[Image: vjPWhyy.gif]
(Feb 19, 2014 02:33 PM)$lick Wrote:  64 - 3 ?

Don't get what you have an issue with

please explain more

I have an application that will do some math to two numbers and then finally mod 64 to it.
Sometimes the final number is positive and sometimes negative.
When it's positive, everything works fine, 76 mod 64 = 12.
When it's negative, it doesn't do anything to it, but from your response I hope it is just simply subtracting it, is that really all i need to do?

example:

if x < 0 then
msgbox( 64 - x )

elseif x > 0 then

msgbox( x mod 64)

end if

Another thing to say, why do other calculations of -3 mod 64 = 61 and in vb it = -3?

Thanks for your response btw! :D
.-=~
Here is the problem:
x mod y = x - (trunctate(x / y) y)

Say x = -3 and y = 64:
-3 / 64 = -0.046875
trunctate(-0.046875) = 0
0
64 = 0
therefore:
-3 - 0 = -3
Conclusion:
-3 mod 64 = -3

----
HOWEVER:

Some mod's use floor instead of trunctate:
Say x = -3 and y = 64:
-3 / 64 = -0.046875
floor(-0.046875) = -1
-1 * 64 = -64
therefore:
-3 - -64 = 61
Conclusion:
-3 mod 64 = 61
--
See the difference?



Use this function:
PHP Code

<?php 
Function _mod(ByVal x As Double, ByVal y As Double) As Double
      
Return x - (Math.Floor(x / y) * y)
    
End Function 
[Image: IQE6i8G.png]

BlackCap Wrote:You're even more verbose than Java.
About using GoTo's in VB/C#:
Only3 Wrote:asm use it why u shouldnt
(Feb 19, 2014 02:53 PM)Temploit Wrote:  Here is the problem:
x mod y = x - (trunctate(x / y) y)

Say x = -3 and y = 64:
-3 / 64 = -0.046875
trunctate(-0.046875) = 0
0
64 = 0
therefore:
-3 - 0 = -3
Conclusion:
-3 mod 64 = -3

----
HOWEVER:

Some mod's use floor instead of trunctate:
Say x = -3 and y = 64:
-3 / 64 = -0.046875
floor(-0.046875) = -1
-1 * 64 = -64
therefore:
-3 - -64 = 61
Conclusion:
-3 mod 64 = 61
--
See the difference?

Thank you very much for shedding some light on this!

EDIT: Just saw your update, works perfectly! Thanks a ton!! :D
.-=~


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by lockheadApr 22, 2021 07:10 AM 0 147 Apr 22, 2021 07:10 AM
Last Post: lockhead
[C] by pmsSep 29, 2019 05:30 AM 1 251 Sep 29, 2019 05:30 AM
Last Post: YouthInAsia
[C] by F.A.S.TMar 8, 2019 12:38 PM 9 491 Mar 8, 2019 12:38 PM
Last Post: F.A.S.T