{$NOMAIN} {$NOWALKBACK} { .STOP File : SC:[22,310]QSUB.PAS Author : Peter Stadick Origin Date : July 2,1988 Edit History : Last Edit: 2-JUL-1988 13:56:10 Description: This routine will subtract two numbers represented arrays of char and return a result as an array of char. Calculations are done to specified number of decimal places and it can handle negitive numbers. The total number of digits in the number can not exceed 18. } %include lb:[22,320]general3.typ; %include de:[107,114]clunk.typ; %include de:[107,114]add64.ext; %include de:[107,114]sub64.ext; %include de:[22,320]castcl.ext; %include de:[22,320]ccltas.ext; procedure qsub(number1 : packed array [ln1..hn1:integer] of char; number2 : packed array [ln2..hn2:integer] of char; var sum : packed array [ls..lh:integer] of char; places : integer; var ids : integer); external; procedure qsub; var clunk1 : clunk_type; clunk2 : clunk_type; clunk_sum : clunk_type; negitive1 : boolean; negitive2 : boolean; negitive_sum : boolean; begin castcl(number1,1,places,negitive1,clunk1); castcl(number2,1,places,negitive2,clunk2); { writeln('1: ',clunk1[1],clunk1[2],clunk1[3],clunk1[4]); writeln('2: ',clunk2[1],clunk2[2],clunk2[3],clunk2[4]); } negitive2 := not negitive2; if (negitive1 and negitive2) or ( not negitive1 and not negitive2) then begin add64(clunk1,clunk2,clunk_sum,ids); negitive_sum := negitive1 and negitive2; end else begin { here only one of the numbers is negitive } if negitive2 then begin sub64(clunk1,clunk2,clunk_sum,ids); if ids < 0 then { if error then clunk2 was greater then clunk1 } begin sub64(clunk2,clunk1,clunk_sum,ids); negitive_sum := true; end else negitive_sum := false; end else begin sub64(clunk2,clunk1,clunk_sum,ids); if ids < 0 then { if error then clunk1 was greater then clunk2 } begin sub64(clunk1,clunk2,clunk_sum,ids); negitive_sum := true; end else negitive_sum := false; end; end; { writeln('SUM:',clunk_sum[1],clunk_sum[2],clunk_sum[3],clunk_sum[4]); } ccltas(clunk_sum,places,negitive_sum,sum); end;