/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <bitset>
using namespace std;
float sqrt(float n) {
cout << "parameter n: "<< n << endl;
int tmp = *(int*)&n;
cout << "After *(int*)&n; " << endl;
cout << "tmp as dec: " << tmp << endl;
cout << "tmp as bin: " << std::bitset<32>(tmp).to_string() << endl;
tmp -= 1 << 23;
cout << "After tmp -= 1 << 23; " << endl;
cout << "tmp as dec: " << tmp << endl;
cout << "tmp as bin: " << std::bitset<32>(tmp).to_string() << endl;
tmp >>= 1;
cout << "After tmp >>= 1; " << endl;
cout << "tmp as dec: " << tmp << endl;
cout << "tmp as bin: " << std::bitset<32>(tmp).to_string() << endl;
tmp += 1 << 29;
cout << "After tmp += 1 << 29; " << endl;
cout << "tmp as dec: " << tmp << endl;
cout << "tmp as bin: " << std::bitset<32>(tmp).to_string() << endl;
cout << "After *(float*)&tmp; " << endl;
return *(float*)&tmp;
}
int main()
{
cout << sqrt(4) << endl;
return 0;
}