int / float

Jul 22, 2018 at 9:03pm
Greetings,

short question:

 
 a = static_cast<float>(150-i*i)/10.0f


a is a float, i is an int.

Why is static_cast necessary? I divide integers by a float, shouldn't this automatically lead to a float value?


Regards
Jul 22, 2018 at 9:16pm
Why is static_cast necessary?

Well in this case the explicit cast is not needed but it does help show intent and it is not wrong to avoid implicit casts.

By the way why are you using float instead of double?

Jul 24, 2018 at 11:39am
Thank you jlb,

I am not using anything, it's from a book :)
Topic archived. No new replies allowed.