Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any numeric suffixes for specifying a double?

Tags:

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.

like image 362
BuckFilledPlatypus Avatar asked Oct 07 '09 22:10

BuckFilledPlatypus


People also ask

How do you define a long double?

In C and related programming languages, long double refers to a floating-point data type that is often more precise than double precision though the language standard only requires it to be at least as precise as double . As with C's other floating-point types, it may not necessarily map to an IEEE format.

What is numeric suffix?

To begin, numeric suffixes are also called literal number suffixes. They are hints to the compiler that a literal number is of a certain type. Literal Recall that "literal" means a value hard-coded into your program. The letters are appended to the end of the literals.

What is the precision of double in C++?

The C++ double should have a floating-point precision of up to 15 digits as it contains a precision that is twice the precision of the float data type. When you declare a variable as double, you should initialize it with a decimal value. For example, 3.0 is a decimal number.

How do you write a long double in C++?

%Lf format specifier for long double %lf and %Lf plays different role in printf. So, we should use %Lf format specifier for printing a long double value.


1 Answers

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

like image 83
JaredPar Avatar answered Oct 21 '22 16:10

JaredPar