sorry for the nooby question but I can't seem to find the answer to this anywhere, probably because I'm unsure what to search for with this problem!

I'm just wondering what the reason is for including a data type in brackets before a calculation takes place? In the code below, all the variables have already been declared at the top of the program, so I'm unsure what the reason / effect of including the (float) has. acc_y and angle_pitch_acc have been declared as floats and acc_total_vector has been declared as long

angle_pitch_acc = asin((float)acc_y/acc_total_vector)* 57.296;


1 Answer 1


It's called casting. It changes the data type temporarily. In this instance it's being used to change an integer type into a floating point type, which means that the whole calculation is done using floating point mathematics. However acc_y is supposedly already a float, but maybe it wasn't at the time the author wrote that line. Maybe things, as they often do in a program, evolved. Only the author knows.

  • The OP wrote, that acc_y is declared as float. So the calculation would already be a floating point one, I think
    – chrisl
    Commented Feb 13, 2021 at 20:22
  • @chrisl I stopped reading at "I wonder..."
    – Majenko
    Commented Feb 13, 2021 at 20:28
  • Ok thanks, that makes sense.
    – Elliot P
    Commented Feb 13, 2021 at 21:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.