SmallInteger.st
changeset 2781 eca37ca06b66
parent 2770 7c4ab842329f
child 2785 3d222249bd61
equal deleted inserted replaced
2780:371b1022e75a 2781:eca37ca06b66
   821     bits = __intVal(self);
   821     bits = __intVal(self);
   822     if (bits == 0) {
   822     if (bits == 0) {
   823 	RETURN ( __MKSMALLINT(-1) );
   823 	RETURN ( __MKSMALLINT(-1) );
   824     }
   824     }
   825 #ifdef alpha64
   825 #ifdef alpha64
   826     mask = 0x2000000000000000;
   826     mask = 0x2000000000000000L;
   827     index = 62;
   827     index = 62;
   828 #else
   828 #else
   829     mask = 0x20000000;
   829     mask = 0x20000000;
   830     index = 30;
   830     index = 30;
   831 #endif
   831 #endif
  1064 signExtendedByteValue
  1064 signExtendedByteValue
  1065     "return a smallInteger from sign-extending the 8'th bit.
  1065     "return a smallInteger from sign-extending the 8'th bit.
  1066      May be useful for communication interfaces"
  1066      May be useful for communication interfaces"
  1067 
  1067 
  1068 %{  /* NOCONTEXT */
  1068 %{  /* NOCONTEXT */
  1069     int i = __intVal(self);
  1069     INT i = __intVal(self);
  1070 
  1070 
  1071     if (i & 0x80) {
  1071     if (i & 0x80) {
  1072 	i = i | 0x7FFFFF00;
  1072 	i = i | 0x7FFFFF00;
  1073     } else {
  1073     } else {
  1074 	i = i & 0x7F;
  1074 	i = i & 0x7F;
  1086 signExtendedShortValue
  1086 signExtendedShortValue
  1087     "return a smallInteger from sign-extending the 16'th bit.
  1087     "return a smallInteger from sign-extending the 16'th bit.
  1088      May be useful for communication interfaces"
  1088      May be useful for communication interfaces"
  1089 
  1089 
  1090 %{  /* NOCONTEXT */
  1090 %{  /* NOCONTEXT */
  1091     int i = __intVal(self);
  1091     INT i = __intVal(self);
  1092 
  1092 
  1093     if (i & 0x8000) {
  1093     if (i & 0x8000) {
  1094 	i = i | 0x7FFF0000;
  1094 	i = i | 0x7FFF0000;
  1095     } else {
  1095     } else {
  1096 	i = i & 0x7FFF;
  1096 	i = i & 0x7FFF;
  2216      * in a global register, which gets destroyed by printf,
  2216      * in a global register, which gets destroyed by printf,
  2217      * manually save it here - very stupid ...
  2217      * manually save it here - very stupid ...
  2218      */
  2218      */
  2219     __BEGIN_PROTECT_REGISTERS__
  2219     __BEGIN_PROTECT_REGISTERS__
  2220 
  2220 
       
  2221 #if INT == long
       
  2222     sprintf(buffer, "%ld", __intVal(self));
       
  2223 #else
  2221     sprintf(buffer, "%d", __intVal(self));
  2224     sprintf(buffer, "%d", __intVal(self));
       
  2225 #endif
  2222 
  2226 
  2223     __END_PROTECT_REGISTERS__
  2227     __END_PROTECT_REGISTERS__
  2224 
  2228 
  2225     newString = __MKSTRING(buffer COMMA_SND);
  2229     newString = __MKSTRING(buffer COMMA_SND);
  2226     if (newString != nil) {
  2230     if (newString != nil) {
  2240     OBJ newString;
  2244     OBJ newString;
  2241 
  2245 
  2242     if (__isSmallInteger(radix)) {
  2246     if (__isSmallInteger(radix)) {
  2243 	switch (__intVal(radix)) {
  2247 	switch (__intVal(radix)) {
  2244 	    case 10:
  2248 	    case 10:
       
  2249 #if INT == long
       
  2250 		format = "%ld";
       
  2251 #else
  2245 		format = "%d";
  2252 		format = "%d";
       
  2253 #endif
  2246 		break;
  2254 		break;
  2247 	    case 16:
  2255 	    case 16:
       
  2256 #if INT == long
       
  2257 		format = "%lx";
       
  2258 #else
  2248 		format = "%x";
  2259 		format = "%x";
       
  2260 #endif
  2249 		break;
  2261 		break;
  2250 	    case 8:
  2262 	    case 8:
       
  2263 #if INT == long
       
  2264 		format = "%lo";
       
  2265 #else
  2251 		format = "%o";
  2266 		format = "%o";
       
  2267 #endif
  2252 		break;
  2268 		break;
  2253 	}
  2269 	}
  2254     }
  2270     }
  2255 
  2271 
  2256     if (format) {
  2272     if (format) {
  2288      return a printed representation of the receiver
  2304      return a printed representation of the receiver
  2289      as specified by formatString, which is defined by the C-
  2305      as specified by formatString, which is defined by the C-
  2290      function 'printf'.
  2306      function 'printf'.
  2291      No checking for string overrun - the resulting string 
  2307      No checking for string overrun - the resulting string 
  2292      must be shorter than 256 chars or else ...
  2308      must be shorter than 256 chars or else ...
  2293      This method is NONSTANDARD and may be removed without notice."
  2309      This method is NONSTANDARD and may be removed without notice;
       
  2310      it is provided to allow special conversions in very special
       
  2311      situaltions.
       
  2312      Notice that a conversion may not be portable; for example,
       
  2313      to correctly convert an int on a 64-bit alpha, a %ld is required,
       
  2314      while other systems may be happy with a %d ...
       
  2315      Use at your own risk (if at all)"
  2294 
  2316 
  2295 %{  /* STACK: 400 */
  2317 %{  /* STACK: 400 */
  2296 
  2318 
  2297     char buffer[256];
  2319     char buffer[256];
  2298     OBJ s;
  2320     OBJ s;
  2457 ! !
  2479 ! !
  2458 
  2480 
  2459 !SmallInteger class methodsFor:'documentation'!
  2481 !SmallInteger class methodsFor:'documentation'!
  2460 
  2482 
  2461 version
  2483 version
  2462     ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.80 1997-07-22 15:45:25 cg Exp $'
  2484     ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.81 1997-07-25 14:25:57 cg Exp $'
  2463 ! !
  2485 ! !