Browse Source

Finish floatScale2

main
邓博昊 8 months ago
parent
commit
c7f180ec6e
2 changed files with 16 additions and 2 deletions
  1. +12
    -1
      LAB1/bits.c
  2. +4
    -1
      README.md

+ 12
- 1
LAB1/bits.c View File

@ -335,7 +335,18 @@ int howManyBits(int x) {
* Rating: 4
*/
unsigned floatScale2(unsigned uf) {
return 2;
unsigned sign = (0x80000000)&uf;
unsigned exp = (0x7f800000)&uf;
unsigned frac = (0x007fffff)&uf;
if(exp == 0x7f800000)
return uf; //exp全为255,frac全是0就是无穷NaNreturn
if(exp == 0x00000000){
if(frac == 0x00000000)
return uf; //exp全为0,frac全为000*2=0
return (frac<<1)|sign|exp;//exp全为0,frac不全为0frac第一位为1时exp变为非全0
}
return (exp+0x00800000)|sign|frac;
}
/*
* floatFloat2Int - Return bit-level equivalent of expression (int) f

+ 4
- 1
README.md View File

@ -25,4 +25,7 @@ A CSAPP LAB
7. Update Makefile
### 2023/10/9 Update:
1. Finish howManyBits
1. Finish howManyBits
### 2023/10/9 Update:
1. Finish floatScale2

Loading…
Cancel
Save