taddcurr.pp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. { %VERSION=1.1 }
  2. {****************************************************************}
  3. { CODE GENERATOR TEST PROGRAM }
  4. {****************************************************************}
  5. { NODE TESTED : secondadd() FPU currency type code }
  6. {****************************************************************}
  7. { PRE-REQUISITES: secondload() }
  8. { secondassign() }
  9. { secondtypeconv() }
  10. {****************************************************************}
  11. { DEFINES: }
  12. { FPC = Target is FreePascal compiler }
  13. {****************************************************************}
  14. { REMARKS: }
  15. { }
  16. { }
  17. { }
  18. {****************************************************************}
  19. { Result is either LOC_FPU or LOC_REFERENCE }
  20. { LEFT NODE (operand) (left operator) }
  21. { LOC_REFERENCE / LOC_MEM }
  22. { LOC_FPU }
  23. { RIGHT NODE (operand) }
  24. { LOC_FPU }
  25. { LOC_REFERENCE / LOC_MEM }
  26. procedure fail;
  27. begin
  28. WriteLn('Failed!');
  29. halt(1);
  30. end;
  31. Procedure CurrencyTestSub;
  32. var
  33. i : Currency;
  34. j : Currency;
  35. result : boolean;
  36. Begin
  37. Write('Currency - Currency test...');
  38. result := true;
  39. i:=99.9;
  40. j:=10.0;
  41. i:=i-j;
  42. if trunc(i) <> trunc(89.9) then
  43. result := false;
  44. WriteLn('Result (89.9) :',i);
  45. i:=j-i;
  46. if trunc(i) <> trunc(-79.9) then
  47. result := false;
  48. WriteLn('Result (-79.9) :',i);
  49. j:=j-10.0;
  50. if j <> 0.0 then
  51. result := false;
  52. WriteLn('Result (0.0) :',j);
  53. if not result then
  54. Fail
  55. else
  56. WriteLn('Success.');
  57. end;
  58. procedure CurrencyTestAdd;
  59. var
  60. i : Currency;
  61. j : Currency;
  62. result : boolean;
  63. Begin
  64. WriteLn('Currency + Currency test...');
  65. result := true;
  66. i:= 9;
  67. i:=i+1.5;
  68. if trunc(i) <> trunc(10.5) then
  69. result := false;
  70. WriteLn('Result (10.5) :',i);
  71. i := 0.0;
  72. j := 100.0;
  73. i := i + j + j + 12.5;
  74. if trunc(i) <> trunc(212.5) then
  75. result := false;
  76. WriteLn('Result (212.5) :',i);
  77. if not result then
  78. Fail
  79. else
  80. WriteLn('Success.');
  81. end;
  82. procedure CurrencyTestmul;
  83. var
  84. i : Currency;
  85. j : Currency;
  86. result : boolean;
  87. begin
  88. WriteLn('Currency * Currency test...');
  89. result := true;
  90. i:= 0;
  91. j:= 0;
  92. i := i * j * i;
  93. if trunc(i) <> trunc(0.0) then
  94. result := false;
  95. WriteLn('Result (0.0) :',i);
  96. i := 10.0;
  97. j := -12.0;
  98. i := i * j * 10.0;
  99. if trunc(i) <> trunc(-1200.0) then
  100. result := false;
  101. WriteLn('Result (-1200.0) :',i);
  102. if not result then
  103. Fail
  104. else
  105. WriteLn('Success.');
  106. end;
  107. Procedure CurrencyTestDiv;
  108. var
  109. i : Currency;
  110. j : Currency;
  111. result : boolean;
  112. Begin
  113. result := true;
  114. WriteLn('Currency / Currency test...');
  115. i:=-99.9;
  116. j:=10.0;
  117. i:=i / j;
  118. if trunc(i) <> trunc(-9.99) then
  119. result := false;
  120. if frac(i) <> frac(-9.99) then
  121. result := false;
  122. WriteLn('Result (-9.99) :',i);
  123. i:=j / i;
  124. if trunc(i) <> trunc(-1.001) then
  125. result := false;
  126. if frac(i) <> frac(-1.001) then
  127. result := false;
  128. WriteLN('Result (-1.001) :',i);
  129. j:=i / 10.0;
  130. if trunc(j) <> trunc(-0.1001) then
  131. result := false;
  132. if frac(j) <> frac(-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 CurrencyTestComplex;
  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 CurrencyTestequal;
  153. var
  154. i : Currency;
  155. j : Currency;
  156. result : boolean;
  157. begin
  158. result := true;
  159. Write('Currency = Currency 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 CurrencyTestnotequal;
  172. var
  173. i : Currency;
  174. j : Currency;
  175. result : boolean;
  176. begin
  177. result := true;
  178. Write('Currency <> Currency 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 CurrencyTestle;
  191. var
  192. i : Currency;
  193. j : Currency;
  194. result : boolean;
  195. begin
  196. result := true;
  197. Write('Currency <= Currency 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 CurrencyTestge;
  216. var
  217. i : Currency;
  218. j : Currency;
  219. result : boolean;
  220. begin
  221. result := true;
  222. Write('Currency >= Currency 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. CurrencyTestEqual;
  242. CurrencyTestNotEqual;
  243. CurrencyTestLE;
  244. CurrencyTestGE;
  245. CurrencyTestSub;
  246. CurrencyTestAdd;
  247. CurrencyTestDiv;
  248. CurrencyTestMul;
  249. { CurrencyTestComplex;}
  250. end.