What is a correct way to convert double to float in c++. Is the conversion implicit?
Question 1: Consider double d = 5.0; and float f;
Which one is correct?
f = d;f = (float)d;f = static_cast<float>(d);
Question 2: Now consider we have
char *buffer = readAllBuffer();
double *d = (const double*)(buffer + offset);
float f;
Which one is now correct?
f = d[0];f = (float)d[0];f = static_cast<float>(d[0]);
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire