View Single Post
Old 2008-01-20, 04:40   Link #1048
Jinto
Asuki-tan Kairin ↓
 
 
Join Date: Feb 2004
Location: Fürth (GER)
Age: 43
Quote:
Originally Posted by monstert View Post
In Java, why is it that you can initialize a variable of type byte or short with an integer literal (as long as you're within the range of allowed number for that data type) but you can't initialize a variable of type float with a floating-point literal without the suffix "f" or casting the literal as a float, even if it's just 0.0?

EDIT 1: lol, i might be reading something incorrectly.

EDIT 2: ah, i see, never mind.

EDIT 3: wait, i still don't get it.
Could be a problem of the compiler. Maybe the numeric value is interpreted as double, and is automatically typecasted to float in the process if you miss the suffix f. The suffix interpretes the value as float and there is no typecast needed then.
Though, every decent compiler should be able to interpret it as float if it is meant to initialize a float variable.
__________________
Folding@Home, Team Animesuki
Jinto is offline   Reply With Quote