Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
!(So efficient)
1. Multiply 1f? Wtf
2. (float) in return? Nooooo
3. That func name tho -
Kimmax111067y@Mitiko noo, just tell the compiler directly that you want float, without any conversations. 1337.1333333337F will do.
Could imagine that your approach could lose accuracy since the number could be interpreted as double before and than be casted to float. Educated guess tho -
eeee31507yI see this all the time and I've used something like:
int i = 1;
float f = i + 0.0F;
Thanks to Java's smart casts for primitives, it works really well. It's short and understandable once you're used to it.
I agree that using it at the core of such a method seems quite bad, though. But it's OK for your everyday number conversions. Just don't try this where precision is important or number overflows can happen.
Related Rants
Found on product core code. 🤔
rant
float