Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Created by Tooster on 04.03.2018.
- //
- #include <cstdint>
- #include <iostream>
- union _A {
- uint32_t mask;
- float f;
- } A1;
- void pf(union _A X) {
- for (int i = 0, j = 0; i < 32; ++i) {
- printf("%d", X.mask & (1 << (31 - i)) ? 1 : 0);
- j++;
- if (j == 8) {
- printf(" ");
- j -= 8;
- }
- }
- printf("\n");
- }
- // multiplies float by 2^i using integer operations on bits
- uint32_t get() {
- A1.mask = 0x00800000;
- int i = 500;
- int32_t m = A1.mask;
- int32_t e = (A1.mask >> 23) & 0xFF;
- if (e + i > 0xFE) return 0x7F800000 | (A1.mask & 0x8000000);
- if (e + i < 1) {
- m = (A1.mask>>(-i))&0x7FFFFF;
- e = 0;
- }
- return (A1.mask&0x80000000)|(std::max(e+i, 0)<<23)|(m&0x7fffff);
- }
- int main() {
- union _A x;
- x.mask = get();
- pf(x);
- printf("%.64f", x.f);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement