Skip to content

Instantly share code, notes, and snippets.

@tomilov
Last active November 16, 2015 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomilov/93ba09f45d2625f5579d to your computer and use it in GitHub Desktop.
Save tomilov/93ba09f45d2625f5579d to your computer and use it in GitHub Desktop.
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cstdlib>
int
main()
{
auto const x = -10000000000000000.0L;
union
{
std::uint8_t in[10];
struct
{
std::uint64_t out8;
std::uint8_t out1;
unsigned : 7;
unsigned sign : 1;
};
};
asm("fld %1\n" "fbstp %0" : "=m"(in) : "f"(x) : "memory");
std::cout << std::hex << std::noshowbase;
if (sign != 0) {
std::cout << '-';
}
if (out1 != 0) {
std::cout << std::uint16_t(out1) << std::setfill('0') << std::setw(16);
}
std::cout << out8 << std::endl;
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment