your issue here is that A CAST IS NOT A CONVERSION:
char *ss = "-1964734.544";
cout<<ss<<endl;
cout<<*reinterpret_cast<double*>(ss)<<endl;
cout<<*(double *)ss<<endl;
is that you're converting a string of characters into a number. What that means is that your memory is containing numbers being ascii values:
"-1964734.544"
is stored in memory as:
45, 49, 57, 54, 52, 55, 51, 52, 46, 53, 52, 52
which is in binary becomes:
00101101,00110001,00111001,00110110,00110100,00110111,00110011,00110100,00101110,00110101,00110100,00110100
within the memory. When converting to double, you're forcing the compiler to consider those numbers being read differently, which is following the IEEE754 way for doubles. And then 45,49,57,52 means something totally different using that encoding of numbers.
Then, considering chars are 8bits and double 32bits, after a cast your memory is then mapped the following way:
00101101001100010011100100110110,
00110100001101110011001100110100,
00101110001101010011010000110100
Then doing a "manual" interpretation to IEEE754 you get three floats:
1.0073988518377597E-11
1.7061830703823944E-7
4.120100094429091E-11
Which oddly is matching none of your values, so your memory sizes could be different, or some magic is happening during the casts.
The good way is to not reinterpret the memory, but to convert the value, and a good solution is to use strtod()
from C, or stod
from the standard library of C++. You'll find many ways to handle the conversion in the other answers or from the posts that duplicates this one.
If you want to have more fun with that just try floats on that webpage.