ID:1664849
 
BYOND Version:506
Operating System:Windows 7 Ultimate 64-bit
Web Browser:Chrome 36.0.1985.143
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
Descriptive Problem Summary: The modulus operator used to (IIRC) be floating-point, and lines such as "Var1 = Var2 % 1" would work, and give the decimal portion of a number. This is not the case; "Var1 = Var2 % 1" will always result in Var1 = 0

Numbered Steps to Reproduce Problem:

Code Snippet (if applicable) to Reproduce Problem:
    world.log << "SubSteps: [SubStepX], [SubStepY] ([NewX], [NewY])"
world.log << "Modulo NewY % 1: [NewY % 1], NewY - round(NewY): [NewY - round(NewY)]"
world.log << "Modulo NewX % 1: [NewX % 1], NewX - round(NewX): [NewX - round(NewX)]"


Expected Results:
Modulo NewY % 1: 0.757324, NewY - round(NewY): 0.757324

Modulo NewX % 1: 0.242615, NewX - round(NewX): 0.242615

Actual Results:
Modulo NewY % 1: 0, NewY - round(NewY): 0.757324

Modulo NewX % 1: 0, NewX - round(NewX): 0.242615

Does the problem occur:
Every time? Or how often? N/A
In other games? N/A
In other user accounts? N/A
On other computers? N/A

When does the problem NOT occur? N/A

Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? Unfortunately, I have no idea at what version this stopped working

Workarounds:
Use "Var1 = Var2 - round(Var2)"
It was never floating point in DM, although I suggested it once to Lummox JR. I'm not sure why it couldn't be added as a function like fmod(), though.
I'm left wondering how it ever worked in my code in the first place, then.
I believe the full work around is actually this:
return (cx/cy-round(cx/cy))*cy


Using round as you did only allows for a denominator in increments of 1 (Which probably works in your case).
In response to Pirion
I'm pretty sure you can distribute the *cy to get cx-round(cx/cy)*cy. Nice find, though.
IT has been a while since I've thought about distrubuting...man..

I know it should be the same, but running through my tests - in 0.4 % 0.00125 - it should be zero, but it is giving a very large result. The max int is 320, so I am not sure why it would be different.

Edit...not distrusting. :/
The modulus operator has never been floating-point in DM. It's always been integer-only. I'd like a floating-point modulo too, but changing the operator itself would impact existing code; I have actually used the integer behavior in some games.
I use the modulus expecting integers constantly. A change to the existing operator would be problematic.

returning the decimal point value of a number is as simple as:

num = num - round(num)
Yeah, I always try to convert floating point values to integers before attempting to use modulus (which makes sense since it deals with acquiring the remainder of the result for integer division).
Bump
3.1 % 3 // rounds to 0 in dm


Below could be the way to include a non-rounded one.?

3.1 %% 0