groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Winnebeck, Jason" <>
Subject Math Operations
Date Fri, 09 Oct 2015 18:23:57 GMT
I've been struggling with types in math operations in Groovy. I think there is an error in
the documentation?

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

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

I would put in a PR to fix up that doc but I'm not sure I understand how it all works. Normally
when I do maths I try to stick all to primitive types or all to BigDecimal types. Today I'm
trying to make sure I don't accidentally go from BigDecimals to float/double.
Jason Winnebeck
Software Engineer III Contractor - IT Software Development | Windstream
600 Willowbrook Office Park, Rochester, NY 14450<> |
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.

View raw message