Weird FMOD/MOD result!

Previous topic - Next topic

Ozden79

I seem to get a very weird result on FMOD/MOD operation which does not happen always.  I'm using this line of code :

ModValueY = FMOD(InGame_CurrentY + InGame_BallY - InGame_BallYShift,32)

And the screenshot you see, from left to right, are the values ModValueY (32), InGame_CurrentY (-48), InGame_BallY  (144) and InGame_BallYShift (0). The FMOD/MOD result should be 0 where it's 32 in this example and I get even weirder results such as 1.2356....-e04 or something.

To make sure, I even recalculate the ModValueY just before the line I print this into the screen so none of the calculation values has changed since I did FMOD and even weirder, there should be no 32 as a result.

Anybody has any idea?

Ãâ€"zden

[attachment deleted by admin]

Moru

This is what I tried, not sure if this is what you did:
Code (glbasic) Select
LOCAL ModValueY=32, InGame_CurrentY=-48, InGame_BallY=555, InGame_BallYShift=0
ModValueY = FMOD(InGame_CurrentY + InGame_BallY - InGame_BallYShift,32)
DEBUG ModValueY
END

Result is 0

You might want to declare everything as integer (ModValueY%), mabe you have some stray floating point somewhere.

Ozden79

Hello There,

Thanks for your response. I agree with you that the behavior I see does not happen everytime, just in some cases and once it happens, I always get the same weird result on the following calculations. I can't use integer values as my game progresses using the gametime and depending on that, values can be non or fractional. The interesting thing is that, the values you see in the screenshot, all of them are integer, otherwise I could blame the precision of my values for that.

Maybe I should send my whole project to Gernot to let him check it as I've one more weird behavior regarding to MouseButton states though it's not that important as it does not break my game mechanic like this one. In the shot you saw, the ball should have fallen onto the blocks but it keeps staying on top of the stars :).

Thanks,

Ãâ€"zden 

Moru

Did you try my code for fixing that mousestatus problem you had or did I completely misunderstand you?
http://www.glbasic.com/forum/index.php?topic=4131.msg30338#msg30338

Ozden79

Hello Moru,

Your code helps to understand whether the mouse is just clicked or was down for a while but when I try it in my case, I see the mouse is still down (even with your code) although both of the mouse buttons has been released and this happens until I click to mouse button once more, than everything get corrected. Also, this only happens at a particular screemn, which is "game completed". At that screen, when I click the mouse button I see it returns to main menu, clicks on new game and even does jump moves within the game if I don't touch it  =D.

About the issue above, I could have a workaround by removing my time based movement on fall down and only using integer fixed step increase/decrease. This did solve the FMOD/MOD behavior (not perfect but you can't understand the difference easily) so this is definiately a hidden precision problem.

I'll still try to share those experiment with Gernot so maybe he can find the real cause of them, whether they are a bug, feature or a mistake made by me.

Thank you all....

Ãâ€"zden

Kitty Hello

why are you using fmod, if you need integers?
I can't reproduce your problem. Also, 1E-4 is just 0.0001, so it's just about zero. where is the problem then?