# float and double

This topic is 5410 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I know that a f or d after a number declares it as a float or a double, but how about 0.0 compared to 0.0f or 0.0d? I just want to know how the compiler (GCC) treats floating point numbers without an 'extension'.

##### Share on other sites
*deleted misinformation*

#include <iostream>void it_is( float ) { std::cout << "It is a float" << std::endl; }void it_is( double) { std::cout << "It is a double"<< std::endl; }int main ( int argc , char ** argv ){    std::cout << "What is 0.0?  "; it_is( 0.0  );    std::cout << "What is 0.0f? "; it_is( 0.0f );    std::cout << "What is 0.0d? "; it_is( 0.0d ); //main.cc:8:43: invalid suffix "d" on floating constant}

[Edited by - MaulingMonkey on September 25, 2004 5:02:22 AM]

##### Share on other sites
Quote:
 Original post by nifeHi, I know that a f or d after a number declares it as a float or a double, but how about 0.0 compared to 0.0f or 0.0d?I just want to know how the compiler (GCC) treats floating point numbers without an 'extension'.

Using a d in that context doesn't make sense, it only works with f to make a float. To mean a double, just use the 0.0 (or just 0.) without anything else (yes, it will always be a double, it's not compiler dependent).

##### Share on other sites
Quote:
 only works with f to make a float. To mean a double, just use the 0.0 (or just 0.) without anything else (yes, it will always be a double, it's not compiler dependent).

Sorry, I just thought I remembered something about a 0.0d, therefore I just tried it, and of course it dídn't work...
And again, sorry, this time for posting without even giving it a try... I must stop relying on my memory ;)

• 21
• 16
• 9
• 17
• 13