Browse Source

Finish floatFloat2Int and Finish datalab

main
邓博昊 7 months ago
parent
commit
4871d61966
2 changed files with 28 additions and 2 deletions
  1. +23
    -1
      LAB1/bits.c
  2. +5
    -1
      README.md

+ 23
- 1
LAB1/bits.c View File

@ -361,6 +361,28 @@ unsigned floatScale2(unsigned uf) {
* Rating: 4
*/
int floatFloat2Int(unsigned uf) {
return 2;
unsigned sign = ((0x80000000)&uf)>>31;
unsigned exp = ((0x7f800000)&uf)>>23;
unsigned frac = (0x007fffff)&uf;
unsigned base = (frac+0x00800000);//1
int bias = (exp-127)-23;//
if(sign==0)
sign = 1;
else
sign = -1;
if(exp == 255)
return 0x80000000u;//
if(exp == 0)
return 0;//
if(bias <=0){
if(bias<=-24)
bias = -24;
return sign*(base>>(-bias));
}
else{
if(bias>=9)
return 0x80000000u;
return sign*(base<<bias);
}
}
// #include "floatPower2.c"

+ 5
- 1
README.md View File

@ -28,4 +28,8 @@ A CSAPP LAB
1. Finish howManyBits
### 2023/10/9 Update:
1. Finish floatScale2
1. Finish floatScale2
2. Finish floatFloat2Int
3. Congratulations!Finish datalab!

Loading…
Cancel
Save