Modulo returns negative when mathematically it shouldn't

1 sentence description of the problem: Modulo returns negative even if mathematically it shouldn’t

Steps to reproduce the problem every time, starting in a blank draft: Set Text to [-27%360] or any negative value modulo positive value

I expected this to happen: not negative (returns 333 in the project)

But instead this happened: negative (returns -27)

Screenshots/video:


Your username: Tri-Angle

Device type, player version & Hopscotch version:
(Or you can include a screenshot of your About page, in :gear: > About)
→ iPad 6th gen, iPadOS15.x, Hopscotch newest version
→ iPhone 6s, iOS 14.x, Hopscotch newest version
→ iPhone 12, iOs 15, Hopscotch newest version

9 Likes

mathematically -27\%360=333, not -27.

5 Likes

I was wondering why some of my code wasn’t working. This has been a problem for a while.

5 Likes

yea, same here. my workaround is (x%y + y)%y (this returns 333 instead of the -27 bug), however one of my code did not work and i reapplied the same thing again (+y%y) which forces it to not give a negative value. it’s super annoying and some people (such as me) will wrongly understand how the modulo operator works

it was a few months ago, when i received this fx9750III graphics 3, that i understood in the hard way that all these years of coding with modulo operator was a lie, and a negative modulo will not output something negative.

5 Likes