是否有指定双精度的数字后缀?

时间:2009-10-07 22:33:06

标签: c++

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

如果没有,演员是否可以实现这一目标?我主要感兴趣的是 在某些操作期间确保双精度数学等:

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?

允许编译器在操作期间自动确定类型的其他提示会很有帮助。

1 个答案:

答案 0 :(得分:36)

C ++中不需要后缀。默认情况下,任何缺少'f'后缀的浮点值都将输入到编译器类型double。

参考:http://en.wikipedia.org/wiki/C_0x