taddreal1.pp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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 (i=j) then
  163. result := false;
  164. if not (i=1000.0) then
  165. result := false;
  166. if not (trunc(i) = trunc(j)) then
  167. result := false;
  168. if not (trunc(i) = trunc(1000.0)) then
  169. result := false;
  170. if not result then
  171. Fail
  172. else
  173. WriteLn('Success.');
  174. end;
  175. procedure realtestnotequal;
  176. var
  177. i : real;
  178. j : real;
  179. result : boolean;
  180. begin
  181. result := true;
  182. Write('Real <> Real test...');
  183. i := 1000.0;
  184. j := 1000.0;
  185. if (i <> j) then
  186. result := false;
  187. if (i <> 1000.0) then
  188. if (trunc(i) <> trunc(j)) then
  189. result := false;
  190. if (trunc(i) <> trunc(1000.0)) then
  191. result := false;
  192. if not result then
  193. Fail
  194. else
  195. WriteLn('Success.');
  196. end;
  197. procedure realtestle;
  198. var
  199. i : real;
  200. j : real;
  201. result : boolean;
  202. begin
  203. result := true;
  204. Write('Real <= Real test...');
  205. i := 1000.0;
  206. j := 1000.0;
  207. if not (i <= j) then
  208. result := false;
  209. if not (i <= 1000.0) then
  210. result := false;
  211. if not (trunc(i) <= trunc(j)) then
  212. result := false;
  213. if not (trunc(i) <= trunc(1000.0)) then
  214. result := false;
  215. i := 10000.0;
  216. j := 999.0;
  217. if trunc(i) < trunc(j) then
  218. result := false;
  219. if trunc(i) < trunc(999.0) then
  220. result := false;
  221. if not result then
  222. Fail
  223. else
  224. WriteLn('Success.');
  225. end;
  226. procedure realtestge;
  227. var
  228. i : real;
  229. j : real;
  230. result : boolean;
  231. begin
  232. result := true;
  233. Write('Real >= Real test...');
  234. i := 1000.0;
  235. j := 1000.0;
  236. if not (i >= j) then
  237. result := false;
  238. if not (i >= 1000.0) then
  239. result := false;
  240. if not (trunc(i) >= trunc(j)) then
  241. result := false;
  242. if not (trunc(i) >= trunc(1000.0)) then
  243. result := false;
  244. i := 999.0;
  245. j := 1000.0;
  246. if i > j then
  247. result := false;
  248. if i > 999.0 then
  249. result := false;
  250. if trunc(i) > trunc(j) then
  251. result := false;
  252. if trunc(i) > trunc(999.0) then
  253. result := false;
  254. if not result then
  255. Fail
  256. else
  257. WriteLn('Success.');
  258. end;
  259. Begin
  260. RealTestEqual;
  261. RealTestNotEqual;
  262. RealTestLE;
  263. RealTestGE;
  264. RealTestSub;
  265. RealTestAdd;
  266. RealTestDiv;
  267. RealTestMul;
  268. { RealTestComplex;}
  269. end.