Commit ae59c24c authored by Cerlane Leong's avatar Cerlane Leong 💬

bug fix on infinity return

parent 4d79424b
......@@ -51,7 +51,7 @@ uint_fast16_t convertFractionP16(double f16, uint_fast8_t fracLength, bool * bit
uint_fast16_t frac=0;
if(f16==0) return 0;
else if(f16==INFINITY) return INFINITY;
else if(f16==INFINITY) return 0x8000;
f16 -= 1; //remove hidden bit
if (fracLength==0)
......@@ -257,7 +257,7 @@ posit16_t convertDoubleToP16(double f16){
uint_fast16_t frac=0;
if(f16==0) return 0;
else if(f16==INFINITY) return INFINITY;
else if(f16==INFINITY) return 0x8000;
f16 -= 1; //remove hidden bit
if (fracLength==0)
......
......@@ -58,7 +58,7 @@ uint_fast32_t convertQuadFractionP32(__float128 f32, uint_fast16_t fracLength, b
uint_fast32_t frac=0;
if(f32==0) return 0;
else if(f32==INFINITY) return INFINITY;
else if(f32==INFINITY) return 0x80000000;
f32 -= 1; //remove hidden bit
if (fracLength==0)
......@@ -473,7 +473,7 @@ uint_fast32_t convertFractionP32(double f32, uint_fast16_t fracLength, bool * bi
uint_fast32_t frac=0;
if(f32==0) return 0;
else if(f32==INFINITY) return INFINITY;
else if(f32==INFINITY) return 0x80000000;
f32 -= 1; //remove hidden bit
if (fracLength==0)
......
......@@ -52,7 +52,7 @@ uint_fast16_t convertFractionP8(double f8, uint_fast8_t fracLength, bool * bitsN
uint_fast8_t frac=0;
if(f8==0) return 0;
else if(f8==INFINITY) return INFINITY;
else if(f8==INFINITY) return 0x80;
f8 -= 1; //remove hidden bit
if (fracLength==0)
......
......@@ -65,8 +65,7 @@ posit_2_t ui32_to_pX2( uint32_t a, int x ) {
}
else {
fracA = a;
//printf("\n\n");
//printBinary(&fracA, 32);
while ( !(fracA & mask) ) {
log2--;
fracA <<= 1;
......@@ -74,11 +73,10 @@ posit_2_t ui32_to_pX2( uint32_t a, int x ) {
k = (log2 >> 2);
expA = (log2 & 0x3) ;
fracA = (fracA ^ mask);
//printBinary(&fracA, 32);
//printf("k: %d expA: %d\n", k, expA);
if(k>=(x-2)){//maxpos
uiA = 0x7FFFFFFF & ((int32_t)0x80000000>>(x-1));
//printBinary(&uZ.ui, 32);
}
else if (k==(x-3)){//bitNPlusOne-> first exp bit //bitLast is zero
uiA = (0x7FFFFFFF ^ (0x3FFFFFFF >> k));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment