C syntax question

Just reading the code for familiarisation. Could someone explain the syntax ".f" in the following line from ArducopterMega.pde please?

G_Dt = (float)delta_ms_fast_loop / 1000.f; // used by DCM integrator

 

Thanks

 

 

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • It forces 1000 to be of type float
  • Developer

     

    The Arducopter code is C++ not C.

     

    f = float qualifier

     

    float is a 32 bits data type with 23 bits for mantissa 8 bits for exposant and 1 bit for sign.

     

    By default, if you type a floating point value into C++ it’s typed as a double. Consequently, if you do something like this:

    float fValue = 4.53; // 4.53 is a double

    You’re assigning a double to a float, which loses precision, and the compiler will probably complain.

    Putting an “f” after the value means that you intend that value to be a float, not a double.

    float fValue = 4.53f; // 4.53 is a float

     

     

  • 3D Robotics
    It means it's a float. It's C++ syntax.
This reply was deleted.

Activity