123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- {****************************************************************}
- { CODE GENERATOR TEST PROGRAM }
- {****************************************************************}
- { NODE TESTED : secondadd() FPU cextended type code }
- {****************************************************************}
- { PRE-REQUISITES: secondload() }
- { secondassign() }
- { secondtypeconv() }
- {****************************************************************}
- { DEFINES: }
- { FPC = Target is FreePascal compiler }
- {****************************************************************}
- { REMARKS: }
- { }
- { }
- { }
- {****************************************************************}
- { Result is either LOC_FPU or LOC_REFERENCE }
- { LEFT NODE (operand) (left operator) }
- { LOC_REFERENCE / LOC_MEM }
- { LOC_FPU }
- { RIGHT NODE (operand) }
- { LOC_FPU }
- { LOC_REFERENCE / LOC_MEM }
- procedure fail;
- begin
- WriteLn('Failed!');
- halt(1);
- end;
- Procedure RealTestSub;
- var
- i : cextended;
- j : cextended;
- result : boolean;
- Begin
- Write('cextended - cextended test...');
- result := true;
- i:=99.9;
- j:=10.0;
- i:=i-j;
- if trunc(i) <> trunc(89.9) then
- result := false;
- WriteLn('Result (89.9) :',i);
- i:=j-i;
- if trunc(i) <> trunc(-79.9) then
- result := false;
- WriteLn('Result (-79.9) :',i);
- j:=j-10.0;
- if j <> 0.0 then
- result := false;
- WriteLn('Result (0.0) :',j);
- if not result then
- Fail
- else
- WriteLn('Success.');
- end;
- procedure RealTestAdd;
- var
- i : cextended;
- j : cextended;
- result : boolean;
- Begin
- WriteLn('cextended + cextended test...');
- result := true;
- i:= 9;
- i:=i+1.5;
- if trunc(i) <> trunc(10.5) then
- result := false;
- WriteLn('Result (10.5) :',i);
- i := 0.0;
- j := 100.0;
- i := i + j + j + 12.5;
- if trunc(i) <> trunc(212.5) then
- result := false;
- WriteLn('Result (212.5) :',i);
- if not result then
- Fail
- else
- WriteLn('Success.');
- end;
- procedure realtestmul;
- var
- i : cextended;
- j : cextended;
- result : boolean;
- begin
- WriteLn('cextended * cextended test...');
- result := true;
- i:= 0;
- j:= 0;
- i := i * j * i;
- if trunc(i) <> trunc(0.0) then
- result := false;
- WriteLn('Result (0.0) :',i);
- i := 10.0;
- j := -12.0;
- i := i * j * 10.0;
- if trunc(i) <> trunc(-1200.0) then
- result := false;
- WriteLn('Result (-1200.0) :',i);
- if not result then
- Fail
- else
- WriteLn('Success.');
- end;
- Procedure RealTestDiv;
- var
- i : cextended;
- j : cextended;
- result : boolean;
- Begin
- result := true;
- WriteLn('cextended / cextended test...');
- i:=-99.9;
- j:=10.0;
- i:=i / j;
- if trunc(i) <> trunc(-9.9) then
- result := false;
- WriteLn('Result (-9.9) :',i);
- i:=j / i;
- if trunc(i) <> trunc(-1.01) then
- result := false;
- WriteLN('Result (-1.01) :',i);
- j:=i / 10.0;
- if trunc(j) <> trunc(-0.1001) then
- result := false;
- WriteLn('Result (-0.1001) :',j);
- if not result then
- Fail
- else
- WriteLn('Success.');
- end;
- { Procedure RealTestComplex;
- var
- i : cextended;
- Begin
- Write('RESULT SHOULD BE 2.09 :');
- i := 4.4;
- WriteLn(Sqrt(i));
- Write('RESULT SHOULD BE PI :');
- WriteLn(Pi);
- Write('RESULT SHOULD BE 4.0 :');
- WriteLn(Round(3.6));
- end;}
- procedure realtestequal;
- var
- i : cextended;
- j : cextended;
- result : boolean;
- begin
- result := true;
- Write('cextended = cextended test...');
- i := 1000.0;
- j := 1000.0;
- if not (trunc(i) = trunc(j)) then
- result := false;
- if not (trunc(i) = trunc(1000.0)) then
- result := false;
- if not result then
- Fail
- else
- WriteLn('Success.');
- end;
- procedure realtestnotequal;
- var
- i : cextended;
- j : cextended;
- result : boolean;
- begin
- result := true;
- Write('cextended <> cextended test...');
- i := 1000.0;
- j := 1000.0;
- if (trunc(i) <> trunc(j)) then
- result := false;
- if (trunc(i) <> trunc(1000.0)) then
- result := false;
- if not result then
- Fail
- else
- WriteLn('Success.');
- end;
- procedure realtestle;
- var
- i : cextended;
- j : cextended;
- result : boolean;
- begin
- result := true;
- Write('cextended <= cextended test...');
- i := 1000.0;
- j := 1000.0;
- if not (trunc(i) <= trunc(j)) then
- result := false;
- if not (trunc(i) <= trunc(1000.0)) then
- result := false;
- i := 10000.0;
- j := 999.0;
- if trunc(i) < trunc(j) then
- result := false;
- if trunc(i) < trunc(999.0) then
- result := false;
- if not result then
- Fail
- else
- WriteLn('Success.');
- end;
- procedure realtestge;
- var
- i : cextended;
- j : cextended;
- result : boolean;
- begin
- result := true;
- Write('cextended >= cextended test...');
- i := 1000.0;
- j := 1000.0;
- if not (trunc(i) >= trunc(j)) then
- result := false;
- if not (trunc(i) >= trunc(1000.0)) then
- result := false;
- i := 999.0;
- j := 1000.0;
- if trunc(i) > trunc(j) then
- result := false;
- if trunc(i) > trunc(999.0) then
- result := false;
- if not result then
- Fail
- else
- WriteLn('Success.');
- end;
- Begin
- RealTestEqual;
- RealTestNotEqual;
- RealTestLE;
- RealTestGE;
- RealTestSub;
- RealTestAdd;
- RealTestDiv;
- RealTestMul;
- { RealTestComplex;}
- end.
|