groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Søren Berg Glasius <soe...@glasius.dk>
Subject Re: Integer primitive division
Date Fri, 23 Oct 2015 21:15:59 GMT
Hi,

I think you can just do

12.intdiv(2)

it will return a java.lang.Number so you will have to cast it to an
java.lang.Integer

Best regards / Med venlig hilsen,
Søren Berg Glasius

Hedevej 1, Gl. Rye, 8680 Ry, Denmark
Mobile: +45 40 44 91 88, Skype: sbglasius
--- Press ESC once to quit - twice to save the changes.

fre. 23. okt. 2015 kl. 22.47 skrev Winnebeck, Jason <
Jason.Winnebeck@windstream.com>:

> Is there any way to perform primitive integer division in Groovy compile
> static mode? If I do:
>
>
>
> (int)(12/2)
>
>
>
> Then it coverts 12 and 2 to Integer objects, calls a method that performs
> BigDecimal division, then calls “as int” (not just intValue) on the result,
> which itself does instanceof checks.
>
>
>
> I tried intdiv, and it is more efficient, but it still converts to and
> from Integer objects so that it can do A.intValue() / B.intValue(), and
> storing that result in an Integer itself.
>
>
>
> I see if I just do 12 + 2, it does a true primitive operation in the
> bytecode. Is there any way to perform primitive division in Groovy the same
> way it is done in Java?
>
>
>
> *Jason Winnebeck*
>
> *Software Engineer III Contractor - IT Software Development | Windstream*
>
> 600 Willowbrook Office Park, Rochester, NY 14450
>
> Jason.Winnebeck@windstream.com | windstreambusiness.com
>
> o: 585.794-4585
>
>
> ------------------------------
> This email message and any attachments are for the sole use of the
> intended recipient(s). Any unauthorized review, use, disclosure or
> distribution is prohibited. If you are not the intended recipient, please
> contact the sender by reply email and destroy all copies of the original
> message and any attachments.
>

Mime
View raw message