Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <float.h>
- #include <math.h>
- #include <stdint.h>
- #include <stdio.h>
- #include <string.h>
- enum {
- FRAC_MASK = (1 << 23) - 1,
- FRAC_WIDTH = 23,
- EXP_MASK = (255 << 23),
- SIGN_MASK = (1 << 31),
- MAX_EXP = 255
- };
- union {
- float fl;
- uint32_t dw;
- } f;
- void f_mul8(float *x) {
- if (isnan(*x)) {
- return;
- }
- f.fl = *x;
- uint32_t exp = (f.dw & EXP_MASK) >> FRAC_WIDTH;
- exp += 3;
- if (exp >= MAX_EXP) {
- *x = (f.dw | SIGN_MASK) | EXP_MASK;
- return;
- }
- f.dw = (f.dw & SIGN_MASK) | (exp << FRAC_WIDTH) | (f.dw & FRAC_MASK);
- *x = f.fl;
- }
- int main() {
- float num;
- if (scanf("%f", &num) == 1) {
- f_mul8(&num);
- printf("%f ", num);
- }
- }
Add Comment
Please, Sign In to add comment