Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use float as default in Java (Eclipse)

I'm justing looking for a way so that i don't have to add 'f' to all my doubles, when programming: e.g.:

FunctionTakingLotsOfFloatsAsParameter( 1.1f , 2.2f , 3.3f , 4.4 );

I want to be able to write this instead:

FunctionTakingLotsOfFloatsAsParameter( 1.1 , 2.2 , 3.3 , 4.4 );

Is there a way to make the compiler creating a float instead of a double as standard non-integer numbers?

like image 908
Marcus Johansson Avatar asked Sep 02 '26 19:09

Marcus Johansson


2 Answers

No. It's fixed in the language specification.

Mind you, it's a good thing it is, it would be one hell of a debug session to find the cause of the sudden precision loss in some builds, compared to the same code built with a different compiler.

One of the basic tenets of Java is that (unlike in C) the language should be as completely specified as possible. You might argue that they sacrificed ease of use here and there but in most cases the value of such a thorough specification is well worth the slight inconvenience it might cause.

like image 129
biziclop Avatar answered Sep 05 '26 09:09

biziclop


Nope.. Do you have a specific reason to use floats in the first place? Doubles are more precise and the memory overhead should IMO be insignificant to justify use of plain floats..

like image 25
Mikko Wilkman Avatar answered Sep 05 '26 07:09

Mikko Wilkman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!