Hi Joost,
try attached patch. For me it works as expected.
-Laco.
Maybe someone else can.

If not, I think we should rewrite the whole function.

Joost.

--- fmtbcd.pp.ori       Mon Jun 20 07:10:16 2011
+++ fmtbcd.pp   Mon Jun 20 07:51:26 2011
@@ -2205,8 +2205,6 @@ writeln;
               bh1[True] := null_.bh;
               FlipFlop := False;
               fdset := p > 0;
-              if fdset
-                then bh.FDig := 0;
               add := 0;
               nz := True;
               while nz do
@@ -2284,9 +2282,6 @@ if p > 3 then halt;
                                 nLDig := 0;
                                 ue := 0;
                                 dd := Singles[lFDig] DIV ( bh2.Singles[lFDig - 
p] + 1 );
-{
-                                dd := 1;
-}
                                 if dd < 1
                                   then dd := 1;
 {
@@ -2316,21 +2311,10 @@ writeln ( 'p=', p, ' dd=', dd, ' lFdig='
                                        end;
 }
                                    end;
-                                            sf := False;
-                                nfdig := lfdig;
-                                nldig := lldig;
+                                sf := False;
+                                nFDig := lFDig;
+                                nLDig := lLDig;
                                 Inc ( Add, dd );
-                                if NOT fdset
-                                  then begin
-                                    bh.FDig := p;
-                                    fdset := True;
-                                   end;
-                                if bh.LDig < p
-                                  then begin
-                                    bh.LDig := p;
-                                    if ( bh.LDig - bh.FDig ) > Succ ( 
MaxFmtBCDFractionSize )
-                                      then nz := False;
-                                   end;
                                 if sf
                                   then nz := False
                                   else begin
@@ -2346,6 +2330,19 @@ writeln ( 'p=', p, ' dd=', dd, ' lFdig='
                            end;
                         if Add <> 0
                           then begin
+
+                            if NOT fdset
+                              then begin
+                                bh.FDig := p;
+                                fdset := True;
+                               end;
+                            if bh.LDig < p
+                              then begin
+                                bh.LDig := p;
+                                if ( bh.LDig - bh.FDig ) > Succ ( 
MaxFmtBCDFractionSize )
+                                  then nz := False;
+                               end;
+
                             i4 := p;
                             while ( Add <> 0 ) AND ( i4 >= bh.FDig ) do
                               begin
program BCDDIV;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes
  { you can add units after this },FmtBCD;

{$R *.res}

var bcd1,bcd2,bcd3:TBCD;
begin
  bcd1:=1000;
  bcd2:=1000;
  BCDDivide(bcd1,bcd2,bcd3);
  writeln(bcdtostr(bcd1), '/', bcdtostr(bcd2), '=', bcdtostr(bcd3));

  bcd1:=1000;
  bcd2:=100;
  BCDDivide(bcd1,bcd2,bcd3);
  writeln(bcdtostr(bcd1), '/', bcdtostr(bcd2), '=', bcdtostr(bcd3));

  bcd2:=10;
  BCDDivide(bcd1,bcd2,bcd3);
  writeln(bcdtostr(bcd1), '/', bcdtostr(bcd2), '=', bcdtostr(bcd3));

  bcd2:=1;
  BCDDivide(bcd1,bcd2,bcd3);
  writeln(bcdtostr(bcd1), '/', bcdtostr(bcd2), '=', bcdtostr(bcd3));

  bcd1:=100;
  bcd2:=2;
  BCDDivide(bcd1,bcd2,bcd3);
  writeln(bcdtostr(bcd1), '/', bcdtostr(bcd2), '=', bcdtostr(bcd3));

  bcd1:=1007;
  bcd2:=5;
  BCDDivide(bcd1,bcd2,bcd3);
  writeln(bcdtostr(bcd1), '/', bcdtostr(bcd2), '=', bcdtostr(bcd3));

  bcd1:=11000;
  bcd2:=11;
  BCDDivide(bcd1,bcd2,bcd3);
  writeln(bcdtostr(bcd1), '/', bcdtostr(bcd2), '=', bcdtostr(bcd3));

  bcd1:=11;
  bcd2:=11000;
  BCDDivide(bcd1,bcd2,bcd3);
  writeln(bcdtostr(bcd1), '/', bcdtostr(bcd2), '=', bcdtostr(bcd3));

  bcd1:=11;
  bcd2:=11;
  BCDDivide(bcd1,bcd2,bcd3);
  writeln(bcdtostr(bcd1), '/', bcdtostr(bcd2), '=', bcdtostr(bcd3));

  readln;
end.

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to