diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2026-09-22 00:34:20 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2026-09-22 00:34:20 +0800 |
| commit | 738971253959dd125303082352354e5fcdfd180f (patch) | |
| tree | 4211ff25cc9735c7c2b6e72fe2e376a31a9d2c4c | |
| parent | d4a06eaf3649f6000ceafc105f37f3349364df00 (diff) | |
| download | datalab2026-738971253959dd125303082352354e5fcdfd180f.tar.gz datalab2026-738971253959dd125303082352354e5fcdfd180f.tar.xz | |
float64_f2i
| -rw-r--r-- | bits.c | 29 |
1 files changed, 28 insertions, 1 deletions
@@ -267,7 +267,34 @@ unsigned floatScale2(unsigned uf) { * Difficulty: 3 */ int float64_f2i(unsigned uf1, unsigned uf2) { - return 2; + unsigned sign = uf2 >> 31; + unsigned exp = (uf2 >> 20) & 0x7FF; + int E; + int mant; + int mag; + int k; + + if (exp < 1023){ + return 0; + } + if (exp >= 1054){ + return ~0x7FFFFFFF; + } + + E = exp - 1023; + mant = (uf2 & 0xFFFFF) | 0x100000; + + if (E <= 20) { + mag = mant >> (20 - E); + } else { + k = E - 20; + mag = (mant << k) | (uf1 >> (32 - k)); + } + + if (sign) { + return -mag; + } + return mag; } /* |
