taddreal3.pp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. {****************************************************************}
  2. { CODE GENERATOR TEST PROGRAM }
  3. {****************************************************************}
  4. { NODE TESTED : secondadd() FPU cextended type code }
  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. procedure fail;
  26. begin
  27. WriteLn('Failed!');
  28. halt(1);
  29. end;
  30. Procedure RealTestSub;
  31. var
  32. i : cextended;
  33. j : cextended;
  34. result : boolean;
  35. Begin
  36. Write('cextended - cextended test...');
  37. result := true;
  38. i:=99.9;
  39. j:=10.0;
  40. i:=i-j;
  41. if trunc(i) <> trunc(89.9) then
  42. result := false;
  43. WriteLn('Result (89.9) :',i);
  44. i:=j-i;
  45. if trunc(i) <> trunc(-79.9) then
  46. result := false;
  47. WriteLn('Result (-79.9) :',i);
  48. j:=j-10.0;
  49. if j <> 0.0 then
  50. result := false;
  51. WriteLn('Result (0.0) :',j);
  52. if not result then
  53. Fail
  54. else
  55. WriteLn('Success.');
  56. end;
  57. procedure RealTestAdd;
  58. var
  59. i : cextended;
  60. j : cextended;
  61. result : boolean;
  62. Begin
  63. WriteLn('cextended + cextended test...');
  64. result := true;
  65. i:= 9;
  66. i:=i+1.5;
  67. if trunc(i) <> trunc(10.5) then
  68. result := false;
  69. WriteLn('Result (10.5) :',i);
  70. i := 0.0;
  71. j := 100.0;
  72. i := i + j + j + 12.5;
  73. if trunc(i) <> trunc(212.5) then
  74. result := false;
  75. WriteLn('Result (212.5) :',i);
  76. if not result then
  77. Fail
  78. else
  79. WriteLn('Success.');
  80. end;
  81. procedure realtestmul;
  82. var
  83. i : cextended;
  84. j : cextended;
  85. result : boolean;
  86. begin
  87. WriteLn('cextended * cextended test...');
  88. result := true;
  89. i:= 0;
  90. j:= 0;
  91. i := i * j * i;
  92. if trunc(i) <> trunc(0.0) then
  93. result := false;
  94. WriteLn('Result (0.0) :',i);
  95. i := 10.0;
  96. j := -12.0;
  97. i := i * j * 10.0;
  98. if trunc(i) <> trunc(-1200.0) then
  99. result := false;
  100. WriteLn('Result (-1200.0) :',i);
  101. if not result then
  102. Fail
  103. else
  104. WriteLn('Success.');
  105. end;
  106. Procedure RealTestDiv;
  107. var
  108. i : cextended;
  109. j : cextended;
  110. result : boolean;
  111. Begin
  112. result := true;
  113. WriteLn('cextended / cextended test...');
  114. i:=-99.9;
  115. j:=10.0;
  116. i:=i / j;
  117. if trunc(i) <> trunc(-9.9) then
  118. result := false;
  119. WriteLn('Result (-9.9) :',i);
  120. i:=j / i;
  121. if trunc(i) <> trunc(-1.01) then
  122. result := false;
  123. WriteLN('Result (-1.01) :',i);
  124. j:=i / 10.0;
  125. if trunc(j) <> trunc(-0.1001) then
  126. result := false;
  127. WriteLn('Result (-0.1001) :',j);
  128. if not result then
  129. Fail
  130. else
  131. WriteLn('Success.');
  132. end;
  133. { Procedure RealTestComplex;
  134. var
  135. i : cextended;
  136. Begin
  137. Write('RESULT SHOULD BE 2.09 :');
  138. i := 4.4;
  139. WriteLn(Sqrt(i));
  140. Write('RESULT SHOULD BE PI :');
  141. WriteLn(Pi);
  142. Write('RESULT SHOULD BE 4.0 :');
  143. WriteLn(Round(3.6));
  144. end;}
  145. procedure realtestequal;
  146. var
  147. i : cextended;
  148. j : cextended;
  149. result : boolean;
  150. begin
  151. result := true;
  152. Write('cextended = cextended test...');
  153. i := 1000.0;
  154. j := 1000.0;
  155. if not (trunc(i) = trunc(j)) then
  156. result := false;
  157. if not (trunc(i) = trunc(1000.0)) then
  158. result := false;
  159. if not result then
  160. Fail
  161. else
  162. WriteLn('Success.');
  163. end;
  164. procedure realtestnotequal;
  165. var
  166. i : cextended;
  167. j : cextended;
  168. result : boolean;
  169. begin
  170. result := true;
  171. Write('cextended <> cextended test...');
  172. i := 1000.0;
  173. j := 1000.0;
  174. if (trunc(i) <> trunc(j)) then
  175. result := false;
  176. if (trunc(i) <> trunc(1000.0)) then
  177. result := false;
  178. if not result then
  179. Fail
  180. else
  181. WriteLn('Success.');
  182. end;
  183. procedure realtestle;
  184. var
  185. i : cextended;
  186. j : cextended;
  187. result : boolean;
  188. begin
  189. result := true;
  190. Write('cextended <= cextended test...');
  191. i := 1000.0;
  192. j := 1000.0;
  193. if not (trunc(i) <= trunc(j)) then
  194. result := false;
  195. if not (trunc(i) <= trunc(1000.0)) then
  196. result := false;
  197. i := 10000.0;
  198. j := 999.0;
  199. if trunc(i) < trunc(j) then
  200. result := false;
  201. if trunc(i) < trunc(999.0) then
  202. result := false;
  203. if not result then
  204. Fail
  205. else
  206. WriteLn('Success.');
  207. end;
  208. procedure realtestge;
  209. var
  210. i : cextended;
  211. j : cextended;
  212. result : boolean;
  213. begin
  214. result := true;
  215. Write('cextended >= cextended test...');
  216. i := 1000.0;
  217. j := 1000.0;
  218. if not (trunc(i) >= trunc(j)) then
  219. result := false;
  220. if not (trunc(i) >= trunc(1000.0)) then
  221. result := false;
  222. i := 999.0;
  223. j := 1000.0;
  224. if trunc(i) > trunc(j) then
  225. result := false;
  226. if trunc(i) > trunc(999.0) then
  227. result := false;
  228. if not result then
  229. Fail
  230. else
  231. WriteLn('Success.');
  232. end;
  233. Begin
  234. RealTestEqual;
  235. RealTestNotEqual;
  236. RealTestLE;
  237. RealTestGE;
  238. RealTestSub;
  239. RealTestAdd;
  240. RealTestDiv;
  241. RealTestMul;
  242. { RealTestComplex;}
  243. end.