groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Winnebeck, Jason" <Jason.Winneb...@windstream.com>
Subject float math in Groovy and IntelliJ
Date Tue, 23 Jan 2018 22:16:26 GMT
I noticed in latest IntelliJ IDEA 2017.3.3 it has started to flag the following code as an
red error, as if it was a compile error:

float a = 1
float b = 2

float c = a + b

It says loss of precision when assigning to c. It is true per http://docs.groovy-lang.org/latest/html/documentation/core-syntax.html#_math_operations
that a float + float is a double, for whatever (probably historical) reason. But this is not
supposed to be a compiler error in compile static mode? It seems as worst case this should
be a warning. But even if it's a warning, is this inappropriate Groovy code? Should c always
be of type double? Should float be avoided? Would a cast always be appropriate style?

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