Browse Source

* fixed small bugs
* fixed some arm issues

florian 21 years ago
parent
commit
9e00ecb080
1 changed files with 30 additions and 24 deletions
  1. 30 24
      rtl/inc/genmath.inc

+ 30 - 24
rtl/inc/genmath.inc

@@ -133,7 +133,7 @@ End;
       aSign: flag;
       aSign: flag;
       aExp, shiftCount: smallint;
       aExp, shiftCount: smallint;
       aSig0, aSig1, absZ, aSigExtra: longint;
       aSig0, aSig1, absZ, aSigExtra: longint;
-      z: smallint;
+      z: longint;
       label invalid;
       label invalid;
    Begin
    Begin
      aSig1 := extractFloat64Frac1( a );
      aSig1 := extractFloat64Frac1( a );
@@ -163,11 +163,11 @@ End;
          aSigExtra := ( aSig0 shl ( shiftCount and 31 ) ) OR  aSig1;
          aSigExtra := ( aSig0 shl ( shiftCount and 31 ) ) OR  aSig1;
          absZ := aSig0 shr ( - shiftCount );
          absZ := aSig0 shr ( - shiftCount );
      End;
      End;
-     if aSign <> 0 then
-       z := - absZ
+     if aSign<>0 then
+       z:=-absZ
      else
      else
-       z := absZ;
-     if ( (( aSign xor flag( z < 0 )) <> 0) AND  (z<>0) ) then
+       z:=absZ;
+     if ((aSign<>0) xor (z<0)) AND  (z<>0) then
      Begin
      Begin
   invalid:
   invalid:
         HandleError(207);
         HandleError(207);
@@ -193,9 +193,6 @@ End;
     extractFloat32Sign := a shr 31;
     extractFloat32Sign := a shr 31;
   End;
   End;
 
 
-
-
-
 Function float32_to_int32_round_to_zero( a: Float32 ): longint;
 Function float32_to_int32_round_to_zero( a: Float32 ): longint;
  Var
  Var
     aSign : flag;
     aSign : flag;
@@ -233,7 +230,6 @@ Function float32_to_int32_round_to_zero( a: Float32 ): longint;
  End;
  End;
 
 
 
 
-  {$warning FIX ME !! }
   function trunc(d : real) : int64;[internconst:in_const_trunc];
   function trunc(d : real) : int64;[internconst:in_const_trunc];
     var
     var
      l: longint;
      l: longint;
@@ -248,6 +244,12 @@ Function float32_to_int32_round_to_zero( a: Float32 ): longint;
      if sizeof(D)=8 then
      if sizeof(D)=8 then
        begin
        begin
          move(d,f64,sizeof(f64));
          move(d,f64,sizeof(f64));
+{$ifdef arm}
+         { the arm fpu has a strange opinion how a double has to be stored }
+         l:=f64.low;
+         f64.low:=f64.high;
+         f64.high:=l;
+{$endif arm}         
          trunc:=float64_to_int32_round_to_zero(f64);
          trunc:=float64_to_int32_round_to_zero(f64);
        end
        end
      else
      else
@@ -272,9 +274,17 @@ Function float32_to_int32_round_to_zero( a: Float32 ): longint;
         i0, j0: longint;
         i0, j0: longint;
         i1: cardinal;
         i1: cardinal;
         sx: longint;
         sx: longint;
+        f64 : float64;
       begin
       begin
-        i0 := float64(d).high;
-        i1 := cardinal(float64(d).low);
+         move(d,f64,sizeof(f64));
+{$ifdef arm}
+         { the arm fpu has a strange opinion how a double has to be stored }
+         i0:=f64.low;
+         f64.low:=f64.high;
+         f64.high:=i0;
+{$endif arm}         
+        i0 := f64.high;
+        i1 := cardinal(f64.low);
         sx := i0 and $80000000;
         sx := i0 and $80000000;
         j0 := ((i0 shr 20) and $7ff) - $3ff;
         j0 := ((i0 shr 20) and $7ff) - $3ff;
         if (j0 < 20) then
         if (j0 < 20) then
@@ -282,13 +292,13 @@ Function float32_to_int32_round_to_zero( a: Float32 ): longint;
             if (j0 < 0) then
             if (j0 < 0) then
               begin
               begin
                 { the magnitude of the number is < 1 so the result is +-0. }
                 { the magnitude of the number is < 1 so the result is +-0. }
-                float64(d).high := sx;
-                float64(d).low := 0;
+                f64.high := sx;
+                f64.low := 0;
               end
               end
             else
             else
               begin
               begin
-                float64(d).high := sx or (i0 and not($fffff shr j0));
-                float64(d).low := 0;
+                f64.high := sx or (i0 and not($fffff shr j0));
+                f64.low := 0;
               end
               end
           end
           end
         else if (j0 > 51) then
         else if (j0 > 51) then
@@ -299,8 +309,8 @@ Function float32_to_int32_round_to_zero( a: Float32 ): longint;
           end
           end
         else
         else
           begin
           begin
-            float64(d).high := i0;
-            float64(d).low := longint(i1 and not(cardinal($ffffffff) shr (j0 - 20)));
+            f64.high := i0;
+            f64.low := longint(i1 and not(cardinal($ffffffff) shr (j0 - 20)));
           end;
           end;
         result := d;
         result := d;
       end;
       end;
@@ -457,9 +467,6 @@ Function float32_to_int32_round_to_zero( a: Float32 ): longint;
     end;
     end;
 
 
 
 
-
-
-
 {$ifndef FPC_SYSTEM_HAS_SQR}
 {$ifndef FPC_SYSTEM_HAS_SQR}
     function sqr(d : Real) : Real;[internconst:in_const_sqr];
     function sqr(d : Real) : Real;[internconst:in_const_sqr];
     begin
     begin
@@ -540,8 +547,6 @@ Function float32_to_int32_round_to_zero( a: Float32 ): longint;
 {$endif}
 {$endif}
 
 
 
 
-
-
 {$ifndef FPC_SYSTEM_HAS_EXP}
 {$ifndef FPC_SYSTEM_HAS_EXP}
     function Exp(d:Real):Real;[internconst:in_const_exp];
     function Exp(d:Real):Real;[internconst:in_const_exp];
     {*****************************************************************}
     {*****************************************************************}
@@ -1184,8 +1189,9 @@ function fpc_int64_to_double(i : int64): double; compilerproc;
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.19  2004-01-24 01:32:00  florian
-    * some const inserted
+  Revision 1.20  2004-01-24 18:15:58  florian
+    * fixed small bugs
+    * fixed some arm issues
 
 
   Revision 1.18  2004/01/06 21:34:07  peter
   Revision 1.18  2004/01/06 21:34:07  peter
     * abs(double) added
     * abs(double) added