/scilab-master-1333395999/modules/integer/src/c/genimpl.c

#
C | 178 lines | 154 code | 13 blank | 11 comment | 16 complexity | ac8713a2875fdd08d749135aeb46f40d MD5 | raw file
  1. /*
  2. * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  3. * Copyright (C) INRIA -
  4. *
  5. * This file must be used under the terms of the CeCILL.
  6. * This source file is licensed as described in the file COPYING, which
  7. * you should have received as part of this distribution. The terms
  8. * are also available at
  9. * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
  10. *
  11. */
  12. #include "genimpl.h"
  13. #define IMPL2(Type) {\
  14. Type FIRST = (Type)*((Type *)first);\
  15. Type LAST = (Type)*((Type *)last);\
  16. Type *RES = (Type *)res;\
  17. Type j;\
  18. i = 0;\
  19. for (j=FIRST;j<=LAST;j++){\
  20. RES[i++]=j;\
  21. }\
  22. }
  23. #define IMPL3(Type) {\
  24. Type FIRST = (Type)*((Type *)first);\
  25. Type STEP = (Type)*((Type *)step);\
  26. Type LAST = (Type)*((Type *)last);\
  27. Type *RES = (Type *)res;\
  28. Type j;\
  29. FIRST=(Type)*((Type *)first);\
  30. LAST=(Type)*((Type *)last);\
  31. STEP=(Type)*((Type *)step);\
  32. RES=(Type *)res;\
  33. i = 0;\
  34. if (STEP<(Type)0) {\
  35. for (j=FIRST;j>=LAST;j+=STEP){\
  36. RES[i++]=j;\
  37. }\
  38. }\
  39. else if (STEP>(Type)0) {\
  40. for (j=FIRST;j<=LAST;j+=STEP){\
  41. RES[i++]=j;\
  42. }\
  43. }\
  44. }
  45. #define IMPL2DIM(Type) {\
  46. Type FIRST = (Type)*((Type *)first);\
  47. Type LAST = (Type)*((Type *)last);\
  48. *res = (int) (LAST-FIRST)+1;\
  49. }
  50. #define IMPL3DIM(Type) {\
  51. Type FIRST = (Type)*((Type *)first);\
  52. Type STEP = (Type)*((Type *)step);\
  53. Type LAST = (Type)*((Type *)last);\
  54. Type j;\
  55. i = 0;\
  56. if (STEP<(Type)0) {\
  57. for (j=FIRST;j>=LAST;j=j+STEP) {i++;}\
  58. }\
  59. else if (STEP>(Type)0) {\
  60. for (j=FIRST;j<=LAST;j=j+STEP) {i++;}\
  61. }\
  62. else {\
  63. i=-1;\
  64. }\
  65. *res = i;\
  66. }
  67. int C2F(genimpl2)(int *typ,int *first,int *last,int *res)
  68. {
  69. static int i;
  70. switch (*typ) {
  71. case 1:
  72. IMPL2(integer1);
  73. break;
  74. case 2:
  75. IMPL2(integer2);
  76. break;
  77. case 4:
  78. IMPL2(int) ;
  79. break;
  80. case 11:
  81. IMPL2(unsigned char);
  82. break;
  83. case 12:
  84. IMPL2(unsigned short);
  85. break;
  86. case 14:
  87. IMPL2(unsigned int);
  88. break;
  89. }
  90. return 0;
  91. }
  92. int C2F(genimpl3)(int *typ,int *first,int *step,int *last,int *res)
  93. {
  94. static int i;
  95. switch (*typ) {
  96. case 1:
  97. IMPL3(integer1);
  98. break;
  99. case 2:
  100. IMPL3(integer2);
  101. break;
  102. case 4:
  103. IMPL3(int) ;
  104. break;
  105. case 11:
  106. IMPL3(unsigned char);
  107. break;
  108. case 12:
  109. IMPL3(unsigned short);
  110. break;
  111. case 14:
  112. IMPL3(unsigned int);
  113. break;
  114. }
  115. return 0;
  116. }
  117. int C2F(genimpl2dim)(int *typ,int *first,int *last,int *res)
  118. {
  119. switch (*typ) {
  120. case 1:
  121. IMPL2DIM(integer1);
  122. break;
  123. case 2:
  124. IMPL2DIM(integer2);
  125. break;
  126. case 4:
  127. IMPL2DIM(int) ;
  128. break;
  129. case 11:
  130. IMPL2DIM(unsigned char);
  131. break;
  132. case 12:
  133. IMPL2DIM(unsigned short);
  134. break;
  135. case 14:
  136. IMPL2DIM(unsigned int);
  137. break;
  138. }
  139. return 0;
  140. }
  141. int C2F(genimpl3dim)(int * typ,int * first,int * step,int * last,int * res)
  142. {
  143. static int i;
  144. switch (*typ) {
  145. case 1:
  146. IMPL3DIM(integer1);
  147. break;
  148. case 2:
  149. IMPL3DIM(integer2);
  150. break;
  151. case 4:
  152. IMPL3DIM(int) ;
  153. break;
  154. case 11:
  155. IMPL3DIM(unsigned char);
  156. break;
  157. case 12:
  158. IMPL3DIM(unsigned short);
  159. break;
  160. case 14:
  161. IMPL3DIM(unsigned int);
  162. break;
  163. }
  164. return 0;
  165. }