Integer add operation now yields Double instead of Long with JDK 1.8.0_101?
Frantzius, Jörg
Joerg.Frantzius at aperto.com
Fri Sep 30 10:26:56 UTC 2016
Hi Attila,
that issue states that Nashorn internally represents numbers as int, long and double, and that now long should not be used anymore. To me this sounds like int can still be used, and I’d think that an int would be more appropriate for representing integral numbers until MAX_INT.
http://openjdk.java.net/jeps/196 states:
* Ensure, by guessing types, that bytecode generated by Nashorn uses as much Java integer arithmetic as possible.
To me this sounds that if long should no longer be used, then int should be used instead when representing integral numbers where possible.
Regards,
Jörg
---
Dipl. Inf. Jörg von Frantzius, Technical Director
E-Mail joerg.frantzius at aperto.com
Phone +49 30 283921-318
Fax +49 30 283921-29
Aperto AG – An IBM Company
Chausseestraße 5, D-10115 Berlin
http://www.aperto.com<http://www.aperto.de/>
http://www.facebook.com/aperto
https://www.xing.com/companies/apertoag
HRB 77049 B, AG Berlin Charlottenburg
Vorstand: Dirk Buddensiek (Vorsitzender), Kai Großmann, Stephan Haagen, Daniel Simon
Aufsichtsrat: Matthew Candy (Vorsitzender)
Am 29.09.2016 um 22:29 schrieb Attila Szegedi <szegedia at gmail.com<mailto:szegedia at gmail.com>>:
It’s an intentional change, see https://bugs.openjdk.java.net/browse/JDK-8144020.
Attila.
On 29 Sep 2016, at 18:30, Frantzius, Jörg <Joerg.Frantzius at aperto.com<mailto:Joerg.Frantzius at aperto.com>> wrote:
Hi,
we have a JUnit test that first evaluates a Javascript file containing this:
function add(a, b) {
return a + b;
}
The Java JUnit test itself then evaluates
engine.eval("add(4, 5)")
Just until 1.8.0_91, this used to return a 9L Long number. With 1.8.0_101, this suddenly returns a Double object 9D.
When directly evaluating the addition operation:
eval("4 + 5")
an Integer 9 is returned, both with 1.8.0_101 and 1.8.0_91.
Is this intended behaviour, or is this a bug?
Thx for responses + regards,
Jörg
---
Dipl. Inf. Jörg von Frantzius, Technical Director
E-Mail joerg.frantzius at aperto.com<mailto:joerg.frantzius at aperto.com>
Phone +49 30 283921-318
Fax +49 30 283921-29
Aperto AG – An IBM Company
Chausseestraße 5, D-10115 Berlin
http://www.aperto.com<http://www.aperto.de/>
http://www.facebook.com/aperto
https://www.xing.com/companies/apertoag
HRB 77049 B, AG Berlin Charlottenburg
Vorstand: Dirk Buddensiek (Vorsitzender), Kai Großmann, Stephan Haagen, Daniel Simon
Aufsichtsrat: Matthew Candy (Vorsitzender)
More information about the nashorn-dev
mailing list