taddreal1.pp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. {****************************************************************}
  2. { CODE GENERATOR TEST PROGRAM }
  3. {****************************************************************}
  4. { NODE TESTED : secondadd() FPU real type code with Emulator }
  5. {****************************************************************}
  6. { PRE-REQUISITES: secondload() }
  7. { secondassign() }
  8. { secondtypeconv() }
  9. {****************************************************************}
  10. { DEFINES: }
  11. { FPC = Target is FreePascal compiler }
  12. {****************************************************************}
  13. { REMARKS: }
  14. { }
  15. { }
  16. { }
  17. {****************************************************************}
  18. { Result is either LOC_FPU or LOC_REFERENCE }
  19. { LEFT NODE (operand) (left operator) }
  20. { LOC_REFERENCE / LOC_MEM }
  21. { LOC_FPU }
  22. { RIGHT NODE (operand) }
  23. { LOC_FPU }
  24. { LOC_REFERENCE / LOC_MEM }
  25. { Only m68k needs FPU emulation }
  26. {$ifdef m68k}
  27. {$define NEEDFPUEMU}
  28. {$endif m68k}
  29. {$ifdef NEEDFPUEMU}
  30. {$E+}
  31. procedure fail;
  32. begin
  33. WriteLn('Failed!');
  34. halt(1);
  35. end;
  36. Procedure RealTestSub;
  37. var
  38. i : Real;
  39. j : Real;
  40. result : boolean;
  41. Begin
  42. Write('Real - Real test...');
  43. result := true;
  44. i:=99.9;
  45. j:=10.0;
  46. i:=i-j;
  47. if trunc(i) <> trunc(89.9) then
  48. result := false;
  49. WriteLn('Result (89.9) :',i);
  50. i:=j-i;
  51. if trunc(i) <> trunc(-79.9) then
  52. result := false;
  53. WriteLn('Result (-79.9) :',i);
  54. j:=j-10.0;
  55. if j <> 0.0 then
  56. result := false;
  57. WriteLn('Result (0.0) :',j);
  58. if not result then
  59. Fail
  60. else
  61. WriteLn('Success.');
  62. end;
  63. procedure RealTestAdd;
  64. var
  65. i : real;
  66. j : real;
  67. result : boolean;
  68. Begin
  69. WriteLn('Real + Real test...');
  70. result := true;
  71. i:= 9;
  72. i:=i+1.5;
  73. if trunc(i) <> trunc(10.5) then
  74. result := false;
  75. WriteLn('Result (10.5) :',i);
  76. i := 0.0;
  77. j := 100.0;
  78. i := i + j + j + 12.5;
  79. if trunc(i) <> trunc(212.5) then
  80. result := false;
  81. WriteLn('Result (212.5) :',i);
  82. if not result then
  83. Fail
  84. else
  85. WriteLn('Success.');
  86. end;
  87. procedure realtestmul;
  88. var
  89. i : real;
  90. j : real;
  91. result : boolean;
  92. begin
  93. WriteLn('Real * Real test...');
  94. result := true;
  95. i:= 0;
  96. j:= 0;
  97. i := i * j * i;
  98. if trunc(i) <> trunc(0.0) then
  99. result := false;
  100. WriteLn('Result (0.0) :',i);
  101. i := 10.0;
  102. j := -12.0;
  103. i := i * j * 10.0;
  104. if trunc(i) <> trunc(-1200.0) then
  105. result := false;
  106. WriteLn('Result (-1200.0) :',i);
  107. if not result then
  108. Fail
  109. else
  110. WriteLn('Success.');
  111. end;
  112. Procedure RealTestDiv;
  113. var
  114. i : Real;
  115. j : Real;
  116. result : boolean;
  117. Begin
  118. result := true;
  119. WriteLn('Real / Real test...');
  120. i:=-99.9;
  121. j:=10.0;
  122. i:=i / j;
  123. if trunc(i) <> trunc(-9.9) then
  124. result := false;
  125. WriteLn('Result (-9.9) :',i);
  126. i:=j / i;
  127. if trunc(i) <> trunc(-1.01) then
  128. result := false;
  129. WriteLN('Result (-1.01) :',i);
  130. j:=i / 10.0;
  131. if trunc(j) <> trunc(-0.1001) then
  132. result := false;
  133. WriteLn('Result (-0.1001) :',j);
  134. if not result then
  135. Fail
  136. else
  137. WriteLn('Success.');
  138. end;
  139. { Procedure RealTestComplex;
  140. var
  141. i : real;
  142. Begin
  143. Write('RESULT SHOULD BE 2.09 :');
  144. i := 4.4;
  145. WriteLn(Sqrt(i));
  146. Write('RESULT SHOULD BE PI :');
  147. WriteLn(Pi);
  148. Write('RESULT SHOULD BE 4.0 :');
  149. WriteLn(Round(3.6));
  150. end;}
  151. procedure realtestequal;
  152. var
  153. i : real;
  154. j : real;
  155. result : boolean;
  156. begin
  157. result := true;
  158. Write('Real = Real test...');
  159. i := 1000.0;
  160. j := 1000.0;
  161. if not (trunc(i) = trunc(j)) then
  162. result := false;
  163. if not (trunc(i) = trunc(1000.0)) then
  164. result := false;
  165. if not result then
  166. Fail
  167. else
  168. WriteLn('Success.');
  169. end;
  170. procedure realtestnotequal;
  171. var
  172. i : real;
  173. j : real;
  174. result : boolean;
  175. begin
  176. result := true;
  177. Write('Real <> Real test...');
  178. i := 1000.0;
  179. j := 1000.0;
  180. if (trunc(i) <> trunc(j)) then
  181. result := false;
  182. if (trunc(i) <> trunc(1000.0)) then
  183. result := false;
  184. if not result then
  185. Fail
  186. else
  187. WriteLn('Success.');
  188. end;
  189. procedure realtestle;
  190. var
  191. i : real;
  192. j : real;
  193. result : boolean;
  194. begin
  195. result := true;
  196. Write('Real <= Real test...');
  197. i := 1000.0;
  198. j := 1000.0;
  199. if not (trunc(i) <= trunc(j)) then
  200. result := false;
  201. if not (trunc(i) <= trunc(1000.0)) then
  202. result := false;
  203. i := 10000.0;
  204. j := 999.0;
  205. if trunc(i) < trunc(j) then
  206. result := false;
  207. if trunc(i) < trunc(999.0) then
  208. result := false;
  209. if not result then
  210. Fail
  211. else
  212. WriteLn('Success.');
  213. end;
  214. procedure realtestge;
  215. var
  216. i : real;
  217. j : real;
  218. result : boolean;
  219. begin
  220. result := true;
  221. Write('Real >= Real test...');
  222. i := 1000.0;
  223. j := 1000.0;
  224. if not (trunc(i) >= trunc(j)) then
  225. result := false;
  226. if not (trunc(i) >= trunc(1000.0)) then
  227. result := false;
  228. i := 999.0;
  229. j := 1000.0;
  230. if trunc(i) > trunc(j) then
  231. result := false;
  232. if trunc(i) > trunc(999.0) then
  233. result := false;
  234. if not result then
  235. Fail
  236. else
  237. WriteLn('Success.');
  238. end;
  239. Begin
  240. RealTestEqual;
  241. RealTestNotEqual;
  242. RealTestLE;
  243. RealTestGE;
  244. RealTestSub;
  245. RealTestAdd;
  246. RealTestDiv;
  247. RealTestMul;
  248. { RealTestComplex;}
  249. end.
  250. {$else NEEDFPUEMU}
  251. begin
  252. writeln('No FPU emulation supported by this platform');
  253. end.
  254. {$endif NEEDFPUEMU}
  255. {
  256. $Log$
  257. Revision 1.3 2002-12-06 15:49:36 peter
  258. * FPU emu is only needed for m68k
  259. Revision 1.2 2002/09/07 15:40:49 peter
  260. * old logs removed and tabs fixed
  261. Revision 1.1 2002/08/25 19:26:23 peter
  262. * splitted in $E+ file and without emulator
  263. Revision 1.5 2002/04/13 21:02:38 carl
  264. * fixed typos
  265. Revision 1.4 2002/03/05 21:55:11 carl
  266. * Adapted for automated testing
  267. }