0

I've started to learn C++ with Stroustrup's C++ programming book - data types. It says that for floating point types language have float, double, long double types. But this program runs good for me:

long float float2{ 5.0F };
cout << float2 << endl;

cout << "size of long float: " << sizeof(long float) << endl; // 8

std::cout << "min long float value: " << (long float)std::numeric_limits<long float>::min() << std::endl; // 2.22507e-308
std::cout << "max long float value: " << (long float)std::numeric_limits<long float>::max() << std::endl << std::endl; // 1.79769e+308

i.e. the same as double. So what's the difference? As far as I knew before there's no such type - long float. Is it the microsoft compiler feature? Is it a new standard?

nikitablack
  • 4,359
  • 2
  • 35
  • 68
  • http://stackoverflow.com/questions/271076/what-is-the-difference-between-an-int-and-a-long-in-c – smali Jun 25 '14 at 10:25
  • 1
    @ali786: That question is about `int` and `long` types. What does it have to do with this question? – Mike Seymour Jun 25 '14 at 10:27
  • Yes you are correct, but In answer one of the user has given good explaination of int and long. In windows both will have 4 bytes of size. – smali Jun 25 '14 at 10:31

2 Answers2

5

So what's the difference?

double is a standard type; long float is not. For example, GCC rejects it: http://ideone.com/0pIhgK.

As far as I knew before there's no such type - long float.

Not in standard C++, no.

Is it the microsoft compiler feature?

Looks like it. That compiler is somewhat notorious for its language "extensions". I believe it has an option to disable (at least some of) them; it would be a good idea to do that, if you want to learn portable C++.

Is it a new standard?

There's no mention of it in C++11, or the latest draft of C++14. The floating point types are specified in 3.9.1/8:

There are three floating point types: float, double, and long double.

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644
  • Thank you. I found that there's warning in my project: warning C4215: nonstandard extension used. And I found this page: http://msdn.microsoft.com/en-us/library/00yasssw.aspx. But setting option to /Za allows for compiling anyway, i.e. there's no compilation error. – nikitablack Jun 25 '14 at 12:35
0

You should be carefull using "long" because it takes more bytes, like an Integer is 4 bytes, an float is 16 bytes. and not sure if you have to use long for a number like "5.0f".

user3742860
  • 100
  • 2
  • 13