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

CEM mod #288

Closed
SoniEx2 opened this issue Oct 12, 2016 · 10 comments
Closed

CEM mod #288

SoniEx2 opened this issue Oct 12, 2016 · 10 comments

Comments

@SoniEx2
Copy link

SoniEx2 commented Oct 12, 2016

The % operator is missing.

@sp614x
Copy link
Owner

sp614x commented Oct 12, 2016

The expressions are operating only on float values and % is not defined for floats.
It could be simulated like:
x % y = ((x / y) - (int)(x / y)) * y

@SoniEx2
Copy link
Author

SoniEx2 commented Oct 12, 2016

What about x % y = x - floor(x / y) * y?

@sp614x
Copy link
Owner

sp614x commented Oct 12, 2016

Practically the same, but it does not work for negative X.
First version works identical to % for negative numbers.

@SoniEx2
Copy link
Author

SoniEx2 commented Oct 12, 2016

The Lua version is saner than the Java version. Let me look up that paper or w/e it was...

@SoniEx2
Copy link
Author

SoniEx2 commented Oct 12, 2016

Meh, couldn't find it...

@SoniEx2
Copy link
Author

SoniEx2 commented Oct 12, 2016

@sp614x
Copy link
Owner

sp614x commented Nov 9, 2016

Not sure which one should be implemented.
The Java version is compatible with most existing C-like languages.
The Lua version is more practical.
Maybe implement "%" as Java defines it and add "mod" as the Lua version?

@SoniEx2
Copy link
Author

SoniEx2 commented Nov 9, 2016

Lua has math.fmod as Java's (well C's really) %. I personally prefer the idea of % as Lua defines it and mod as Java defines it.

@sp614x
Copy link
Owner

sp614x commented Nov 9, 2016

For me defining "%" like Java and "mod" like Lua is the better way. Most other languages (except Lua) define "%" in the C/Java way (the result sign differs a bit).

Most of the time "%" is used as "x % y == 0" in order to trigger an action every "y" steps. For this usage both implementation are working correctly and the practical difference will be minimal.

Java has the Lua mod as Math.floorMod() so I could use "fmod" for it.

@sp614x
Copy link
Owner

sp614x commented Nov 10, 2016

Added:

  • operator "%" - similar to Java "%"
  • function "fmod(x,y)" - similar to Math.floorMod()

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

No branches or pull requests

2 participants