diff options
author | Julian T <julian@jtle.dk> | 2020-10-12 16:26:42 +0200 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2020-10-12 16:54:48 +0200 |
commit | 4e05a55e373bd315e721d534a1711fec4c0054c5 (patch) | |
tree | 4fc0141760c2730ed79aaa4c7aa60ea45cc66cc0 /sem4/embedded/emb_m2 | |
parent | b7f9cf43c8a9ab3400cbb30d5e1cadb0c6c2cf23 (diff) |
Moved to linux kernel inspired clang-format
Diffstat (limited to 'sem4/embedded/emb_m2')
-rw-r--r-- | sem4/embedded/emb_m2/myfloat_red.h | 69 |
1 files changed, 33 insertions, 36 deletions
diff --git a/sem4/embedded/emb_m2/myfloat_red.h b/sem4/embedded/emb_m2/myfloat_red.h index b553233..142d0bc 100644 --- a/sem4/embedded/emb_m2/myfloat_red.h +++ b/sem4/embedded/emb_m2/myfloat_red.h @@ -4,54 +4,51 @@ */ //low precision floating pt type -typedef struct myfloat -{ - signed char mantissa; - signed char exponent; +typedef struct myfloat { + signed char mantissa; + signed char exponent; } myfloat_type; - //convert from double to low precision type void doub2mydouble(double arg, myfloat_type *res) { - int exponent; - double temp; - exponent = ceil(log(abs(arg))/log(2)); //base 2 logarithm - temp=arg*pow(2,7-exponent); - res->mantissa = (signed char)temp; - res->exponent = exponent-7; + int exponent; + double temp; + exponent = ceil(log(abs(arg)) / log(2)); //base 2 logarithm + temp = arg * pow(2, 7 - exponent); + res->mantissa = (signed char)temp; + res->exponent = exponent - 7; } //convert from low precision type to double double myfloat2double(myfloat_type *arg1) { - double res = (double)(arg1->mantissa) * pow(2,arg1->exponent); - return res; + double res = (double)(arg1->mantissa) * pow(2, arg1->exponent); + return res; } //multiply to low precision types -void mult_float(myfloat_type *arg1,myfloat_type *arg2,myfloat_type *result) +void mult_float(myfloat_type *arg1, myfloat_type *arg2, myfloat_type *result) { - int temp; - unsigned char sign; - - sign=0x80 & ((unsigned char)arg1-> mantissa ^ (unsigned char)arg2-> mantissa); //find sign of result - - char i=0; - temp = (int)(arg1-> mantissa) * (int)(arg2-> mantissa); - - temp = temp & 0x7f00; //take away sign from product - - while(abs(temp)>128) - { - i++; - temp=temp>>1; - } - - result->mantissa = (unsigned char) temp; - - result->mantissa = result->mantissa | sign; //add recorded sign - - result->exponent = arg1->exponent + arg2->exponent + i; - + int temp; + unsigned char sign; + + sign = 0x80 & ((unsigned char)arg1->mantissa ^ + (unsigned char)arg2->mantissa); //find sign of result + + char i = 0; + temp = (int)(arg1->mantissa) * (int)(arg2->mantissa); + + temp = temp & 0x7f00; //take away sign from product + + while (abs(temp) > 128) { + i++; + temp = temp >> 1; + } + + result->mantissa = (unsigned char)temp; + + result->mantissa = result->mantissa | sign; //add recorded sign + + result->exponent = arg1->exponent + arg2->exponent + i; } |