ERangeError in BCDDivide
Original Reporter info from Mantis: Bart @flyingsheep
-
Reporter name: Bart Broersma
Original Reporter info from Mantis: Bart @flyingsheep
- Reporter name: Bart Broersma
Description:
Unexpected ERangeError can occur in BCDDivide
See testprogram below, it fails on 7,14,21,26,27,28,34,35,37,38, 41,42, 51,52,53,54,56,57,61,63,65,68,70 and 6615.
Steps to reproduce:
program bcd;
{$mode objfpc}
uses
sysutils, fmtbcd;
type
TIntArray = array of Integer;
var
B,D,R:TBCD;
S:String;
Test: TIntArray;
N: Integer;
begin
Test := TIntArray.Create(1,6,7,8,13,14,15,21,22,25,26,27,28,29,33,34,35,36,37,38,39,40,41,42,
43,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,
6615);
//failed numbers I've found so far.
//6615(original)7,14,21,26,27,28,34,35,37,38, 41,42, 51,52,53,54,56,57,61,63,65,68,70
R := StrToBCD('0.0'); //Just to make sure.
B := StrToBCD('224518.0639999999994919');
for N in Test do
begin
D := IntegerToBCD(N);
try
BCDDivide(B,D,R);
S := BCDtoStr(R);
writeln(N,' -> ',S);
except
on E: ERangeError do writeln(N,' -> ERangeError');
end;
end;
end.
Additional information:
Originally reported in the forum: http://forum.lazarus.freepascal.org/index.php/topic,41379.0.html