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

get(), set() -- cast double to int #261

Open
jeremydouglass opened this issue Apr 17, 2020 · 0 comments
Open

get(), set() -- cast double to int #261

jeremydouglass opened this issue Apr 17, 2020 · 0 comments

Comments

@jeremydouglass
Copy link
Member

  • Typical Processing sketch math involves division to find an index for get()ing or set()ing a pixel.
  • In Java this works fine with integer division and integer modulo, which return an integer.
  • In R / Renjin, however, division or modulo (mod() or %%) of two integers returns double -- and "integer division" also returns a double with an integer value.
  • The result is that passing the result of almost any operation to get() / set() needs to be cast to be safely used, or it crashes the sketch with a signature type error -- this is unexpected for Processing users.
  • The solution, casting with as.integer(), is verbose and not in any of the non-R reference examples because it is not idiomatic in the Processing API, where the normal way of casting is with int() or (int).

The best solution is probably to add a casting signature which converts (double, double) to (int, nit) to BuiltinApplet.java.

src/rprocessing/applet/BuiltinApplet.java

For past examples see #155 , 2f1f865

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

1 participant