taddreal1.pp 6.2 KB

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