float math in Groovy and IntelliJ

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

float math in Groovy and IntelliJ

Winnebeck, Jason
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
[hidden email] | 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.