Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2011-06

divide bcd's

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Joost van der Sluis

Hi all,

Dividing BCD's doesn't go wel:

100/1=10
100/2=overflow
1007/5=overflow

It's all in this function in the FmtBCD unit:

procedure BCDDivide ( const Dividend,
                              Divisor : tBCD;
                          var BCDout : tBCD );

I've tried to understand how the code works. I think it tries to implement the algorithm as described here:
http://media.digikey.com/PDF/Reference%20Design/Digi-Key%20DDS%20group/DKAN0003A_BCD_Division.pdf

But I can't follow. Florian checked in the original code. Did he wrote it himself? It could be that there's just a small problem with an index or something. But I can't find it. Maybe someone else can.

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

Joost.

Reply by email

LacaK
to Joost van der Sluis

Hi Joost,
for me:

100/1=10 <--error
10/1=10
100/10=10
1000/1=10 <--error
1000/10=10 <--error
1000/100=10
100/2=50
1007/5=201.4

-Laco.

Show quoted text 26 lines
Hi all, Dividing BCD's doesn't go wel: 100/1=10 100/2=overflow 1007/5=overflow It's all in this function in the FmtBCD unit: procedure BCDDivide ( const Dividend, Divisor : tBCD; var BCDout : tBCD ); I've tried to understand how the code works. I think it tries to implement the algorithm as described here: http://media.digikey.com/PDF/Reference%20Design/Digi-Key%20DDS%20group/DKAN0003A_BCD_Division.pdf But I can't follow. Florian checked in the original code. Did he wrote it himself? It could be that there's just a small problem with an index or something. But I can't find it. Maybe someone else can. If not, I think we should rewrite the whole function. Joost.

Reply by email

LacaK
to LacaK

To not forget, I have reported it also in bug tracker http://bugs.freepascal.org/view.php?id=19636
-Laco.

Show quoted text 15 lines
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. > ------------------------------------------------------------------------ _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email