none
declare variable double xxx= 0.0f; vs. double xxx= 0.0;

    Question

  • Hi,

    A dumb question, I noticed this notation in the code I was analyzing.  What does it mean?

    double xxx= 0.0f;
     vs.
    double xxx= 0.0;

    I guess the "f" just stands for float but why is this necessary?

    Thanks
    Wednesday, September 30, 2009 7:24 PM

Answers

  • 0.0f forces the number to be treated as a single precision floating point number (float).  Normally, you'd only use this for assigning to a float:

    float xxx = 0.0f;

    When you do:

    double xxx = 0.0;

    It uses the standard, which is equivalent to:

    double xxx = 0.0l;  // long double


    For full details, see Literals (C++) , and more specifically, C++ Floating-Point Constants .


    However, since a float can be assigned to a double and widens automatically, in your case, you get the same value.
    Reed Copsey, Jr. - http://reedcopsey.com
    • Marked as answer by Jeffs_Programs Wednesday, September 30, 2009 7:39 PM
    Wednesday, September 30, 2009 7:37 PM