vendredi 26 février 2016

Get 32 MSB/LSB of double in C/C++?

How do I get the 32 MSB and LSB of a double? Is this correct please?

double d;
uint64_t scale64 = *reinterpret_cast<uint64_t *>(&d); // or memcpy(&scale64, &d, sizeof(uint64_t));
uint32_t msb = (uint32_t)(scale64 >> 32);
uint32_t lsb = (uint32_t)scale64;

Aucun commentaire:

Enregistrer un commentaire