Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modulo operator doesn't consider negative values correctly. #2643

Open
cuckydev opened this issue Feb 29, 2024 · 2 comments
Open

Modulo operator doesn't consider negative values correctly. #2643

cuckydev opened this issue Feb 29, 2024 · 2 comments

Comments

@cuckydev
Copy link

Currently, roblox-ts transpiles the modulo operator directly to a Lua modulo operator. This is an issue as in Lua, the modulo operator will always return a positive value, while TypeScript will return a negative value if the dividend is negative.

Consider the following assertions (copied from the MDN web docs)
https://roblox-ts.com/playground/#code/IYZxFMCcBcAoEYDMACApMgrMgvL5iBKAbgChQIZYBaJNTHPKw08qOAFjoCYHtkAGYmTBtqndD1x9BpIA

This will pass when ran in TypeScript, but fail when ran through roblox-ts.

You can check this right now by running the following snippets:

TypeScript/JavaScript (run in the Inspect Element console window)

console.assert(13 % 5 === 3);
console.assert(-13 % 5 === -3);
console.assert(4 % 2 === 0);
console.assert(-4 % 2 === 0);

Lua (run in the Roblox command line)

assert(13 % 5 == 3);
assert(-13 % 5 == -3);
assert(4 % 2 == 0);
assert(-4 % 2 == 0);

This seems unintentional, as roblox-ts takes measures to ensure parity with TypeScript in the case of things such as array indices starting from 0, where they start from 1 in Lua.

@dyslexicsteak
Copy link
Contributor

I'll try to get it fixed, thanks

@dyslexicsteak
Copy link
Contributor

After talking about this off-platform with the maintainer and some contributors, I want to let you know that fixing this issue is technically breaking. Therefore, depending on the project's direction, it may or may not be resolved in version 3.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants