I have the following code, where I copy a double in to a buffer. I then copy the value in the buffer back to a double but get the value 0.94999999999999996. How can I make sure it is 0.95 that is copied/read from the buffer?
double value_from = 0.95;
std::uint8_t *data = new std::uint8_t[sizeof(value_from)];
memset(data, 0x00, sizeof(value_from));
memcpy(data, &value_from, sizeof(value_from));
double value_to = 0;
memcpy(&value_to, data, sizeof(value_to));