Is there any compiler that has a directive or a parameter to cast integer calculation to float implicitly. For example:
float f = (1/3)*5;
cout << f;
the "f" is "0", because calculation's constants(1, 3, 10) are integer. I want to convert integer calculation with a compiler directive or parameter. I mean, I won't use explicit casting or ".f" prefix like that:
float f = ((float)1/3)*5;
or
float f = (1.0f/3.0f)*5.0f;
Do you know any c/c++ compiler which has any parameter to do this process without explicit casting or ".f" thing?
1and3need to be float. The other constant and the5will automatically promote. Also you do not need to define them to befloat, doubles will be implicitly demoted to float:float f = (1.0 / 3)*5will make the trick (or5.0/3).floattodouble) but when both integral and floating points are involved they are called 'conversions'