Export to GitHub

google-web-toolkit - issue #9224

Math.rint is very slow and needs to be translated to JS Math.round


Posted on Jul 15, 2015 by Grumpy Kangaroo

Found in GWT Release 2.7, trunk Encountered on OS / Browser (e.g. WinXP, IE9, FF10): All

Detailed description (please be as specific as possible):

Math.rint is very slow. This happens because it goes via slow and unnecessary conversion via long (call to "long round(double)")

Shortest code snippet which demonstrates issue (please indicate where actual result differs from expected result): call to Math.rint

patch:

  • public static native double rint(double x) /*-{
  • return Math.round(x);
  • }-*/;

  • public static double rint(double d) {

  • if (Double.isNaN(d)) {
  • return d;
  • } else if (Double.isInfinite(d)) {
  • return d;
  • } else if (d == 0.0d) {
  • return d;
  • } else {
  • return round(d);
  • }
  • }

Comment #1

Posted on Jul 16, 2015 by Swift Rhino

The issue tracker has moved to GitHub: http://www.gwtproject.org/lifeofanissue.html Would you mind reopening the issue there?

Also, BTW, would you mind submitting the patch to Gerrit? http://www.gwtproject.org/makinggwtbetter.html#contributingcode

Finally, note that rint() has a different (expected) behavior than round() (e.g. rint(4.5) is 4.0, but round(4.5) is 5), but it apparently is already "broken" in the current implementation.

Comment #2

Posted on Jul 16, 2015 by Grumpy Kangaroo

I (re)opened an issue there https://github.com/gwtproject/gwt/issues/9156

Thanks for suggestion.

Status: Invalid

Labels:
Category-JRE