Skip to content

Instantly share code, notes, and snippets.

@orontee
Created September 25, 2013 16:40
Show Gist options
  • Save orontee/6702404 to your computer and use it in GitHub Desktop.
Save orontee/6702404 to your computer and use it in GitHub Desktop.
#include <iostream>
int main()
{
float f(32767); // 32768
signed short sshf = static_cast<signed short>(f);
signed short rshf = *(reinterpret_cast<signed short*>(&f));
std::cout << "As float: "
<< f << " (" << sizeof(float) << ")\n"
<< "Static cast as signed short: "
<< sshf << " (" << sizeof(signed short) << ")\n"
<< "Reinterpret as signed short: "
<< rshf << " (" << sizeof(signed short) << ")\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment