* device/include/float.h: added __INFINITY
[fw/sdcc] / device / lib / _fsadd.c
index 8d3c6ab3acd4cd9970139fdb0886e2e7cacd2851..cb179c5e9644ccf75724580ac0226e478ab1b720 100644 (file)
 
 #ifdef FLOAT_ASM_MCS51
 
-// float __fsadd (float a, float b) reentrant
-static void dummy(void) _naked
+// float __fsadd (float a, float b) __reentrant
+static void dummy(void) __naked
 {
-       _asm
+       __asm
 
        // extract the two inputs, placing them into:
        //      sign     exponent   mantiassa
@@ -128,7 +128,7 @@ fsadd_direct_entry:
        lcall   fs_normalize_a
        ljmp    fs_round_and_return
 
-       _endasm;
+       __endasm;
 }
 
 #else
@@ -150,7 +150,6 @@ fsadd_direct_entry:
 ** uunet!motown!pipeline!phw
 */
 
-
 union float_long
   {
     float f;
@@ -163,7 +162,7 @@ float __fsadd (float a1, float a2)
   volatile long mant1, mant2;
   volatile union float_long fl1, fl2;
   volatile int exp1, exp2;
-  volatile unsigned long sign = 0;
+  char sign = 0;
 
   fl1.f = a1;
   fl2.f = a2;
@@ -204,7 +203,7 @@ float __fsadd (float a1, float a2)
   if (mant1 < 0)
     {
       mant1 = -mant1;
-      sign = SIGNBIT;
+      sign = 1;
     }
   else if (!mant1)
     return (0);
@@ -219,7 +218,7 @@ float __fsadd (float a1, float a2)
   while (mant1 & 0xff000000) {
     if (mant1&1)
       mant1 += 2;
-    mant1 >>= 1 ;
+    mant1 >>= 1;
     exp1++;
   }
 
@@ -227,10 +226,13 @@ float __fsadd (float a1, float a2)
   mant1 &= ~HIDDEN;
 
   /* pack up and go home */
-  fl1.l = PACK (sign, (unsigned long) exp1, mant1);
-
+  if (exp1 >= 0x100)
+    fl1.l = (sign ? SIGNBIT : 0) | __INFINITY;
+  else if (exp1 < 0)
+    fl1.l = 0;
+  else
+    fl1.l = PACK (sign ? SIGNBIT : 0 , exp1, mant1);
   return (fl1.f);
 }
 
 #endif
-