summaryrefslogtreecommitdiff
path: root/fpcsrc/tests/test/units/math/tdivmod.pp
blob: 5a3752055e587bd76108d2fdd53f7f51048313bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
{$mode objfpc}
uses
  math;
{ tests:
  procedure DivMod(Dividend: Integer; Divisor: Word;  var Result, Remainder: Word);
  procedure DivMod(Dividend: Integer; Divisor: Word; var Result, Remainder: SmallInt);
  procedure DivMod(Dividend: DWord; Divisor: DWord; var Result, Remainder: DWord);
  procedure DivMod(Dividend: Integer; Divisor: Integer; var Result, Remainder: Integer);
}
procedure doerror(i : integer);
  begin
    writeln('Error: ',i);
	halt(1);
  end;


var
  QuotientWord,RemainderWord : Word;
  QuotientSmallInt,RemainderSmallInt : SmallInt;
  QuotientDWord,RemainderDWord : DWord;
  QuotientInteger,RemainderInteger : Integer;

begin
  DivMod($ffff,65,QuotientWord,RemainderWord);
  if QuotientWord<>1008 then
    doerror(1);
  if RemainderWord<>15 then
    doerror(2);
	
  DivMod($ffff,65,QuotientSmallInt,RemainderSmallInt);
  if QuotientSmallInt<>1008 then
    doerror(1001);
  if RemainderSmallInt<>15 then
    doerror(2);
	
  DivMod($ffff,65,QuotientDWord,RemainderDWord);
  if QuotientDWord<>1008 then
    doerror(2001);
  if RemainderDWord<>15 then
    doerror(2002);

  DivMod(123456,23,QuotientDWord,RemainderDWord);
  if QuotientDWord<>5367 then
    doerror(2003);
  if RemainderDWord<>15 then
    doerror(2004);

  DivMod($ffff,65,QuotientInteger,RemainderInteger);
  if QuotientInteger<>1008 then
    doerror(3001);
  if RemainderInteger<>15 then
    doerror(3002);

  DivMod(123456,23,QuotientInteger,RemainderInteger);
  if QuotientInteger<>5367 then
    doerror(3003);
  if RemainderInteger<>15 then
    doerror(3004);
	
  DivMod(-9, 5, QuotientInteger,RemainderInteger);
  if QuotientInteger<>-1 then
    doerror(3005);
  if RemainderInteger<>-4 then
    doerror(3006);
	
  DivMod(-9, -5, QuotientInteger,RemainderInteger);
  if QuotientInteger<>1 then
    doerror(3007);
  if RemainderInteger<>-4 then
    doerror(3008);
	
end.