What is the difference between LONG float and double in C ++?

So, I know that there is a big difference in the accuracy of floats and doubles. I understand. Promise

But, in C ++, when scanf and printf are called, the notation used to indicate double is "% lf", and that means long float, right? So, although a float is less accurate than a double, a LONG float (supposedly called a long float, because it can be "longer" with more terms), has the same precision and therefore is essentially the same?

Just to clarify, here is what I mean:

double number = 3.14159; printf("The number is %lf", number); 

So, the root of my question is: long floating another name for double?

+6
source share
3 answers

In my knowledge there is no such thing as long float .

This post gives you information on why people use lf to print double with printf , if that is the cause of your confusion.

By courtesy @ Jerry Coffin:

"% f" is (or at least "a") the correct format for the double. There is no format for float, because if you try to pass a float to printf, it will be asked to double before receiving printf. "% lf" is also acceptable according to the current standard - - l is listed as having no effect if you follow the conversion specifier f (among others).

So the reason is that when people do:

  printf("The number is %lf", number); 

This is equivalent to:

 printf("The number is %f", number); //l has no effect when printing double 
+14
source

printf qualifier names have nothing to do with type names.

They are simply named so that they are short and easy to remember.

float โ†’ double โ†’ long double

% f โ†’% lf โ†’% Lf

(also they could not name printf double specifier as %d , because this name is already reserved for the decimal representation of int (compared to the octal %o ))

@taocp's answer explains why you can use %f and %lf with printf , but note that you cannot do this with scanf

+4
source

For scanf you pass a pointer to the place where the result will be saved; you read the float value with %f and the double value with %lf ; you must distinguish between them, because float and double should not have the same representation. For printf you pass the displayed value, and float values โ€‹โ€‹get to double , because they are passed as arguments to ... the prototype part; those. for printf there is no difference between a float and a double , so %f and %lf do the same.

0
source

Source: https://habr.com/ru/post/946287/


All Articles