Thread: float declaration problem

  1. #1
    Registered User
    Join Date
    Nov 2006

    Cool float declaration problem

    In a sample program, I found some strange declaration in it.

    float deltaY = 1.0f;
    float halfDeltaY = .5f;
    what do they mean? Simply deltaY = 1.0 and halfDeltaY = 0.5?
    Last edited by rosicky2005; 11-06-2006 at 09:19 PM.

  2. #2
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Chch, NZ
    if you write a floating point literal in C++ (i.e. 3.14) the compiler interprets it as a double precision float (or more simple as type double).

    the f suffix simply tells the compiler you're explicitly requesting a float type.

    this is present with other literals as well
    int x = 1;
    int y = 010; // is actually octal
    assert(y == 8);
    unsigned char = 128u; // tells the compiler the value is unsigned (i.e. 0 to 255, instead of -128 to 127)
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Float Function Issues
    By GCNDoug in forum C++ Programming
    Replies: 5
    Last Post: 10-29-2007, 03:25 PM
  2. Debug Error Really Quick Question
    By GCNDoug in forum C Programming
    Replies: 1
    Last Post: 04-23-2007, 12:05 PM
  3. Opengl walking leg animation
    By Bobby230 in forum C Programming
    Replies: 3
    Last Post: 03-05-2006, 03:41 PM
  4. Integration problem
    By HAssan in forum C Programming
    Replies: 4
    Last Post: 01-23-2006, 03:07 AM
  5. error declaration terminated incorrectly help
    By belfour in forum C++ Programming
    Replies: 7
    Last Post: 11-25-2002, 09:07 PM