You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@groovy.apache.org by Edmond Kemokai <ek...@gmail.com> on 2019/12/08 20:26:48 UTC
Groovy multiplication
Is there a reason this should yield a negative number in groovy?
86400*1000*30
Re: Groovy multiplication
Posted by Paul King <pa...@asert.com.au>.
I don't believe it is. It is that most primitive ints are converted to
java.lang.Integer unless primitive optimization is in place.
Cheers, Paul.
On Tue, Dec 10, 2019 at 10:22 AM Jochen Theodorou <bl...@gmx.org> wrote:
> On 09.12.19 18:04, Milles, Eric (TR Tech, Content & Ops) wrote:
> > If you disable the compiler’s primitive optimization, then integer
> > literals will be BigInteger.
>
> That is not supposed to be the case.
>
> bye blackdrag
>
Re: Groovy multiplication
Posted by Jochen Theodorou <bl...@gmx.org>.
On 09.12.19 18:04, Milles, Eric (TR Tech, Content & Ops) wrote:
> If you disable the compiler’s primitive optimization, then integer
> literals will be BigInteger.
That is not supposed to be the case.
bye blackdrag
RE: Groovy multiplication
Posted by "Milles, Eric (TR Tech, Content & Ops)" <er...@thomsonreuters.com>.
If you disable the compiler’s primitive optimization, then integer literals will be BigInteger.
From: Paul King <pa...@asert.com.au>
Sent: Monday, December 9, 2019 11:01 AM
To: Groovy_Developers <de...@groovy.apache.org>
Subject: Re: Groovy multiplication
Meta note: This thread is related to the usage of Groovy and best belongs on the users mailing list where it will gain more eyeballs and also more likely to be found in the future by other users in the same scenario. The dev list is for aspects relating to the development of the language itself.
But to answer the current question, Integer literals aren't made BigInteger by default but if either side of a multiplication is a BigInteger, the answer will be BigInteger, so you get the correct answer in the posed problem with e.g.: 86400G*1000*30
Cheers, Paul.
On Tue, Dec 10, 2019 at 2:48 AM Angelo Schneider <an...@oomentor.de>> wrote:
Would that not be handled by BigInteger?
I assumed integer literals are treated as BigInter just like float/double literals are treated as BigDecimals.
Greetings
Angelo
Am 09.12.2019 um 00:51 schrieb Edmond Kemokai <ek...@gmail.com>>:
I'd read up on the MAX_VALUE doc but didn't see any mention of this behavior... Thanks guys!!
Re: Groovy multiplication
Posted by MG <mg...@arscreat.com>.
Hi guys,
speaking as a Groovy user again (i.e. irrespective of how hard this
would be to change/implement) and as someonewho has run into the same
problem: This seems very Java & mighty un-groovy to me.
At least if the calculation is done in a single statement (but also for
constant numerical values in general), I would expect one of two
behaviors: Either
1. Throw a compilation error, saying that the result cannot be
represented within the literal datatype given (with a hint that
appending "L" or "G" might be what the user wants), or
2. Automatically use BigInteger as the result type.
Gauging whether the product of several integer literals fits within a
32-bit int is not something humans are typically good at, and a
numerical overflow is basically always an error. During runtime overflow
error detection is typically off, due to performance considerations, but
this would not prohibit it during compile time...
Cheers,
mg
On 09/12/2019 18:00, Paul King wrote:
> Meta note: This thread is related to the usage of Groovy and best
> belongs on the users mailing list where it will gain more eyeballs and
> also more likely to be found in the future by other users in the same
> scenario. The dev list is for aspects relating to the development of
> the language itself.
>
> But to answer the current question, Integer literals aren't made
> BigInteger by default but if either side of a multiplication is a
> BigInteger, the answer will be BigInteger, so you get the correct
> answer in the posed problem with e.g.: 86400G*1000*30
>
> Cheers, Paul.
>
>
> On Tue, Dec 10, 2019 at 2:48 AM Angelo Schneider
> <angelo.schneider@oomentor.de <ma...@oomentor.de>>
> wrote:
>
> Would that not be handled by BigInteger?
>
> I assumed integer literals are treated as BigInter just like
> float/double literals are treated as BigDecimals.
>
> Greetings
> Angelo
>
> Am 09.12.2019 um 00:51 schrieb Edmond Kemokai <ekemokai@gmail.com
> <ma...@gmail.com>>:
>
>> I'd read up on the MAX_VALUE doc but didn't see any mention of
>> this behavior... Thanks guys!!
>>
>
Re: Groovy multiplication
Posted by Paul King <pa...@asert.com.au>.
Meta note: This thread is related to the usage of Groovy and best belongs
on the users mailing list where it will gain more eyeballs and also more
likely to be found in the future by other users in the same scenario. The
dev list is for aspects relating to the development of the language itself.
But to answer the current question, Integer literals aren't made BigInteger
by default but if either side of a multiplication is a BigInteger, the
answer will be BigInteger, so you get the correct answer in the posed
problem with e.g.: 86400G*1000*30
Cheers, Paul.
On Tue, Dec 10, 2019 at 2:48 AM Angelo Schneider <
angelo.schneider@oomentor.de> wrote:
> Would that not be handled by BigInteger?
>
> I assumed integer literals are treated as BigInter just like float/double
> literals are treated as BigDecimals.
>
> Greetings
> Angelo
>
> Am 09.12.2019 um 00:51 schrieb Edmond Kemokai <ek...@gmail.com>:
>
> I'd read up on the MAX_VALUE doc but didn't see any mention of this
> behavior... Thanks guys!!
>
>
>
Re: Groovy multiplication
Posted by Angelo Schneider <an...@oomentor.de>.
Would that not be handled by BigInteger?
I assumed integer literals are treated as BigInter just like float/double literals are treated as BigDecimals.
Greetings
Angelo
Am 09.12.2019 um 00:51 schrieb Edmond Kemokai <ek...@gmail.com>:
> I'd read up on the MAX_VALUE doc but didn't see any mention of this behavior... Thanks guys!!
>
Re: Groovy multiplication
Posted by Edmond Kemokai <ek...@gmail.com>.
I'd read up on the MAX_VALUE doc but didn't see any mention of this
behavior... Thanks guys!!
Re: Groovy multiplication
Posted by Keith Suderman <su...@cs.vassar.edu>.
The same reason it does in Java; the result is larger than Integer.MAX_VALUE (ie. integer overflow). You need to tell Java/Groovy to use a larger type.
System.out.println(86400L*1000*30);
> On Dec 8, 2019, at 3:26 PM, Edmond Kemokai <ek...@gmail.com> wrote:
>
> Is there a reason this should yield a negative number in groovy?
>
> 86400*1000*30
>
Re: Groovy multiplication
Posted by "Daniel.Sun" <su...@apache.org>.
Hi Edmond,
How about 86400G * 1000 * 30
Cheers,
Daniel.Sun
-----
Apache Groovy committer & PMC member
Blog: http://blog.sunlan.me
Twitter: @daniel_sun
--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html