Résultat du TP en C sur Forth
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmpop.c 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include "cmpop.h"
  2. #include "num.h"
  3. #include "pile.h"
  4. int equali(int i, int j) {
  5. if ( i == j ) {
  6. return -1;
  7. } else {
  8. return 0;
  9. }
  10. }
  11. int equalf(float i, float j) {
  12. if ( i == j ) {
  13. return -1;
  14. } else {
  15. return 0;
  16. }
  17. }
  18. int lessThani(int i, int j) {
  19. if ( i < j ) {
  20. return -1;
  21. } else {
  22. return 0;
  23. }
  24. }
  25. int lessThanf(float i, float j) {
  26. if ( i < j ) {
  27. return -1;
  28. } else {
  29. return 0;
  30. }
  31. }
  32. int greaterThani(int i, int j) {
  33. if ( i > j ) {
  34. return -1;
  35. } else {
  36. return 0;
  37. }
  38. }
  39. int greaterThanf(float i, float j) {
  40. if ( i > j ) {
  41. return -1;
  42. } else {
  43. return 0;
  44. }
  45. }
  46. void cmpop( int (*opint)(int,int), int (*opfloat)(float,float), struct Pile* pile ) {
  47. struct NumContainer res;
  48. struct NumContainer num1;
  49. struct NumContainer num2;
  50. getlastnums(&num1, &num2, pile);
  51. push(pile, num1);
  52. /* getlastnums(&num1, &num2, pile); */
  53. res.t = INT;
  54. if ( num1.t == INT ) {
  55. if ( num2.t == INT ) {
  56. res.n.vali = opint( num1.n.vali, num2.n.vali );
  57. } else {
  58. res.n.valf = opfloat((float)num1.n.vali, num2.n.valf);
  59. }
  60. } else {
  61. if ( num2.t == INT ) {
  62. res.n.valf = opfloat(num1.n.valf, (float)num2.n.vali);
  63. } else {
  64. res.n.valf = opfloat(num1.n.valf, num2.n.valf);
  65. }
  66. }
  67. push(pile, res);
  68. }
  69. void equal(struct State* state) {
  70. if (state->mode == EXECUTE) {
  71. cmpop(equali, equalf, &state->pile);
  72. }
  73. }
  74. void less(struct State* state) {
  75. if (state->mode == EXECUTE) {
  76. cmpop(lessThani, lessThanf, &state->pile);
  77. }
  78. }
  79. void greater(struct State* state) {
  80. if (state->mode == EXECUTE) {
  81. cmpop(greaterThani, greaterThanf, &state->pile);
  82. }
  83. }