Device type, player version & Hopscotch version:
(Or you can include a screenshot of your About page, in > About)
→ iPad 6th gen, iPadOS15.x, Hopscotch newest version
→ iPhone 6s, iOS 14.x, Hopscotch newest version
→ iPhone 12, iOs 15, Hopscotch newest version
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.
(-27 % 360) returns -27 in JavaScript, which is why it returned -27 in our code. So if anything, it’s a bug in the JavaScript language, not just the app.
Main reason is because % is not a modulo operation, it’s a remainder operation. There is no actual modulo operator in JavaScript…
(((x%y)+y)%y) is the actual solution to the way JavaScript behaves. Your way works too.
“The JavaScript %(modulo) behaves like a remainder operation and gives the remainder and as the number is negative therefore remainder also comes out to be negative.” ~ Google
So yeah, believe it or not, this is actually intentional, according to how JavaScript works…