tags:

views:

149

answers:

1
void Foo(float  a){}  //1
void Foo(double a){}  //2 overloaded


Foo(1.0f);                           //calls function 1
Foo(1.0 /*double numeric suffix?*/); //calls function 2

If not, is a cast the only way this can be achieved? I am mainly interested in ensuring double precision math during certain operations, etc:

ulong j;
double v;

j = /*some value*/;
if(j>0UL)
  v = 1.0 / j;  //if 1.0 is set as a float by the compiler then
                //could it be likely we lose some precision here 
                //if a double would allow for more precision?  Is
                //a cast the only means of ensuring double precision?

Other tips on allowing the compiler to auto-determine the types during an operation would be helpful.

+6  A: 

A suffix is unnecessary in C++. Any floating point value which lacks the 'f' suffix will be typed to the compiler type double by default.

Reference: http://en.wikipedia.org/wiki/C_0x

JaredPar
Exactly the information I need. Thank you.
BuckFilledPlatypus