OK, so int + BigDecimal is a bug in documentation then.

I am using Groovy Shell (2.4.3, JVM: 1.8.0_45), and in that I run this:

groovy:000> println (((byte)1 + (short)1).class)
class java.lang.Byte
===> null
groovy:000> println ((byte)1 + (short)1)
2
===> null

I wondered if Groovy was somehow picking the "smallest" type, because byte + 
short -> byte makes no sense at all unless Groovy was looking at the result. 
However, this doesn't look good at all:
groovy:000> println ((byte)1 + (short)700)
-67

It looks like it really is doing the math as bytes. What version of Groovy are 
you using where it works?

Jason

-----Original Message-----
From: Jochen Theodorou [mailto:blackd...@gmx.org] 
Sent: Friday, October 09, 2015 2:46 PM
To: users@groovy.incubator.apache.org
Subject: Re: Math Operations

Am 09.10.2015 um 20:23 schrieb Winnebeck, Jason:
> I've been struggling with types in math operations in Groovy. I think 
> there is an error in the documentation?
>
> http://groovy-lang.org/syntax.html#_math_operations
>
> It says that int and BigDecimal result in double, but it doesn't, it 
> results in BigDecimal instead. It appears this holds for byte, char, 
> short, and long as well.
> assert (15.0 + 1).class == BigDecimal

integral type with BigDecimal should lead to BigDecimal. So yes, that's a bug.


> Are there other errors in that table? It seems so... because byte + short
> is a byte and not an int as mentioned in that table:
>
> assert ((byte)1 + (short)1).class == Byte

that assert fails for me. I get int (well Integer).

Anyway.... the BigDecimal part in that table looks wrong... BigDecimal 
leads always to BigDecimal, except for float/double.

bye blackdrag

-- 
Jochen "blackdrag" Theodorou
blog: http://blackdragsview.blogspot.com/

----------------------------------------------------------------------
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.

Reply via email to