Explorar el Código

* fixed + optimized generic round_real
- removed cgenmath version of round_real because it wasn't any better
than the generic one anymore

git-svn-id: trunk@11295 -

Jonas Maebe hace 17 años
padre
commit
310ec39757
Se han modificado 2 ficheros con 15 adiciones y 57 borrados
  1. 0 43
      rtl/inc/cgenmath.inc
  2. 15 14
      rtl/inc/genmath.inc

+ 0 - 43
rtl/inc/cgenmath.inc

@@ -96,49 +96,6 @@
 {$endif}
 
 
-{ Not supported everywhere (also not on Mac OS X 10.1, but that's deprecated. }
-{ It is supported on linux, but at least for linux/i386 we should call        }
-{ llroundl() instead (for extended support).                                  }
-
-{$if defined(darwin) }
-
-{$ifndef FPC_SYSTEM_HAS_ROUND}
-{$define FPC_SYSTEM_HAS_ROUND}
-
-    function c_llround(d: double): int64; cdecl; external 'c' name 'llround';
-
-    function fpc_round_real(d : ValReal) : int64;[public, alias:'FPC_ROUND'];compilerproc;
-    begin
-      case softfloat_rounding_mode of
-        float_round_nearest_even:
-          begin
-            fpc_round_real:=c_llround(d);
-            { llround always rounds half-way cases away from zero, }
-            { regardless of the current rounding mode              }
-            if (abs(frac(d))=0.5) then
-              fpc_round_real:=2*trunc(fpc_round_real*extended(0.5));
-          end;
-        float_round_down:
-          if (d>=0) or
-             (frac(d)=0.0) then
-            result:=trunc(d)
-          else
-            result:=trunc(d-1.0);
-        float_round_up:
-          if (d>=0) and
-             (frac(d)<>0.0) then
-            result:=trunc(d+1.0)
-          else
-            result:=trunc(d);
-        float_round_to_zero:
-          result:=trunc(d);
-      end;
-    end;
-{$endif not FPC_SYSTEM_HAS_ROUND}
-
-{$endif darwin}
-
-
 {$ifndef FPC_SYSTEM_HAS_LN}
 {$define FPC_SYSTEM_HAS_LN}
 

+ 15 - 14
rtl/inc/genmath.inc

@@ -941,14 +941,14 @@ invalid:
 {$ifndef FPC_SYSTEM_HAS_ROUND}
     function fpc_round_real(d : ValReal) : int64;compilerproc;
      var
-      fr: Real;
+      fr: ValReal;
       tr: Int64;
     Begin
+      fr := abs(Frac(d));
+      tr := Trunc(d);
       case softfloat_rounding_mode of
         float_round_nearest_even:
           begin
-            fr := abs(Frac(d));
-            tr := Trunc(d);
             if fr > 0.5 then
               if d >= 0 then
                 result:=tr+1
@@ -964,24 +964,25 @@ invalid:
                 if d >= 0.0 then
                   result:=tr+1
                 else
-                  result:=tr-1;
-                result:=2*trunc(result*0.5);
+                  result:=tr;
+                { round to even }
+                result:=result and not(1);
               end;
           end;
         float_round_down:
-          if (d>=0) or
-             (frac(d)=0.0) then
-            result:=trunc(d)
+          if (d >= 0.0) or
+             (fr = 0.0) then
+            result:=tr
           else
-            result:=trunc(d-1.0);
+            result:=tr-1;
         float_round_up:
-          if (d>=0) and
-             (frac(d)<>0.0) then
-            result:=trunc(d+1.0)
+          if (d >= 0.0) and
+             (fr <> 0.0) then
+            result:=tr+1
           else
-            result:=trunc(d);
+            result:=tr;
         float_round_to_zero:
-          result:=trunc(d);
+          result:=tr;
       end;
     end;
 {$endif FPC_SYSTEM_HAS_ROUND}