fork download
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <cfloat> // _controlfp
  3. #include <cmath> // sqrt
  4. #include <string>
  5. #include <algorithm>
  6. #include <iostream>
  7. using namespace std;
  8.  
  9. void print_bits(const double& value){
  10. auto raw=*(unsigned long long*)&value;
  11. auto len=sizeof(raw)<<3;
  12. auto str=string(len,(char)0);
  13. for_each(begin(str),end(str),[&raw](char&chr){
  14. chr=(raw&1)?'1':'0';
  15. raw>>=1;
  16. });
  17. reverse(begin(str),end(str));
  18. cout<<"0b"<<str<<endl;
  19. }
  20.  
  21. void print_bits(const float& value){
  22. auto raw=*(unsigned int*)&value;
  23. auto len=sizeof(raw)<<3;
  24. auto str=string(len,(char)0);
  25. for_each(begin(str),end(str),[&raw](char&chr){
  26. chr=(raw&1)?'1':'0';
  27. raw>>=1;
  28. });
  29. reverse(begin(str),end(str));
  30. cout<<"0b"<<str<<endl;
  31. }
  32.  
  33. #define _PC_64 0x00000000
  34. #define _PC_53 0x00010000
  35. #define _PC_24 0x00020000
  36. #define _MCW_PC 0x00030000
  37.  
  38. int main(){
  39. _controlfp(_PC_24,_MCW_PC);
  40. print_bits(sqrt((float)2));
  41. print_bits(sqrt((double)2));
  42. _controlfp(_PC_53,_MCW_PC);
  43. print_bits(sqrt((float)2));
  44. print_bits(sqrt((double)2));
  45. _controlfp(_PC_64,_MCW_PC);
  46. print_bits(sqrt((float)2));
  47. print_bits(sqrt((double)2));
  48. }
  49. // VCにて(x86)
  50. //0b00111111101101010000010011110011
  51. //0b0011111111110110101000001001111001100000000000000000000000000000
  52. //0b00111111101101010000010011110011
  53. //0b0011111111110110101000001001111001100110011111110011101111001101
  54. //0b00111111101101010000010011110011
  55. //0b0011111111110110101000001001111001100110011111110011101111001101
  56.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty