強迫float做低階運算的方法
float a, b;
long i;
a=0.1;
b=0.2;
i=*(long*)&a^*(long*)&b;
a=*(float*)&i;
i=*(long*)&a^*(long*)&b;
b=*(float*)&i;
i=*(long*)&a^*(long*)&b;
a=*(float*)&i;
=========================================
float a=4.3,b=2.4;
*(long*)&a = *(long*)&a ^ *(long*)&b;
*(long*)&b = *(long*)&b ^ *(long*)&a;
*(long*)&a = *(long*)&a ^ *(long*)&b;
cout << a << ", " << b << endl ;
沒有留言:
張貼留言