How is double represented on arduino?

I wanted to see how arduino represents doubles so I could send them over serial port, so I tried

Serial.begin();
double x = 58.285;
for (int i = 0; i < 8; i++){
   Serial.println((unsigned char)*((char*)&x+i));
}

which prints out

215
35
105
66
0
52
0
91

but no matter how I arrange these bytes, I never get the original number. For getting the original number I used in rust

f64::from_le_bytes([215, 35, 105, 66, 0, 52, 0, 91]);

with some permutations of numbers. For float it works fine without even need to rearrange it, so what's the problem with double?

Try using sizeof to see how big that double actually is.

8 bit or 32 bit Arduino ?

on a 8 bit a double is really just a float (single precision)
on a 32 bit microcontroller then you get 8 bytes and a "real" double

On most arduino's double is not actually implemented, but will use float instead.

Thanks a lot, I never considered an option that it is just a float. When I tried that, it worked perfectly.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.