equal
deleted
inserted
replaced
10 hereby transferred. |
10 hereby transferred. |
11 " |
11 " |
12 "{ Package: 'stx:libbasic' }" |
12 "{ Package: 'stx:libbasic' }" |
13 |
13 |
14 Number subclass:#Integer |
14 Number subclass:#Integer |
15 instanceVariableNames:'' |
15 instanceVariableNames:'' |
16 classVariableNames:'DefaultDisplayRadix BCDConversionErrorSignal PrimeCache' |
16 classVariableNames:'DefaultDisplayRadix BCDConversionErrorSignal PrimeCache' |
17 poolDictionaries:'' |
17 poolDictionaries:'' |
18 category:'Magnitude-Numbers' |
18 category:'Magnitude-Numbers' |
19 ! |
19 ! |
20 |
20 |
21 Object subclass:#ModuloNumber |
21 Object subclass:#ModuloNumber |
22 instanceVariableNames:'modulus reciprocal shift' |
22 instanceVariableNames:'modulus reciprocal shift' |
23 classVariableNames:'' |
23 classVariableNames:'' |
24 poolDictionaries:'' |
24 poolDictionaries:'' |
25 privateIn:Integer |
25 privateIn:Integer |
26 ! |
26 ! |
27 |
27 |
28 !Integer class methodsFor:'documentation'! |
28 !Integer class methodsFor:'documentation'! |
29 |
29 |
30 copyright |
30 copyright |
756 ^ BCDConversionErrorSignal |
756 ^ BCDConversionErrorSignal |
757 |
757 |
758 "Modified: / 15.11.1999 / 20:35:20 / cg" |
758 "Modified: / 15.11.1999 / 20:35:20 / cg" |
759 ! ! |
759 ! ! |
760 |
760 |
|
761 |
|
762 |
761 !Integer class methodsFor:'class initialization'! |
763 !Integer class methodsFor:'class initialization'! |
762 |
764 |
763 initialize |
765 initialize |
764 BCDConversionErrorSignal isNil ifTrue:[ |
766 BCDConversionErrorSignal isNil ifTrue:[ |
765 BCDConversionErrorSignal := ConversionError newSignal. |
767 BCDConversionErrorSignal := ConversionError newSignal. |
815 " |
817 " |
816 Integer displayRadix:16. 123456 inspect |
818 Integer displayRadix:16. 123456 inspect |
817 Integer displayRadix:10. 123456 inspect |
819 Integer displayRadix:10. 123456 inspect |
818 " |
820 " |
819 ! ! |
821 ! ! |
|
822 |
820 |
823 |
821 !Integer class methodsFor:'prime numbers'! |
824 !Integer class methodsFor:'prime numbers'! |
822 |
825 |
823 flushPrimeCache |
826 flushPrimeCache |
824 "cleanup after using a primeCache" |
827 "cleanup after using a primeCache" |
1138 Abstract subclasses must redefine again." |
1141 Abstract subclasses must redefine again." |
1139 |
1142 |
1140 ^ self == Integer |
1143 ^ self == Integer |
1141 ! ! |
1144 ! ! |
1142 |
1145 |
|
1146 |
1143 !Integer methodsFor:'Compatibility-Dolphin'! |
1147 !Integer methodsFor:'Compatibility-Dolphin'! |
1144 |
1148 |
1145 & aNumber |
1149 & aNumber |
1146 "return the bitwise-and of the receiver and the argument, anInteger. |
1150 "return the bitwise-and of the receiver and the argument, anInteger. |
1147 Same as bitAnd: - added for compatibility with Dolphin Smalltalk. |
1151 Same as bitAnd: - added for compatibility with Dolphin Smalltalk. |
1237 !Integer methodsFor:'Compatibility-Squeak'! |
1241 !Integer methodsFor:'Compatibility-Squeak'! |
1238 |
1242 |
1239 asByteArray |
1243 asByteArray |
1240 "return my hexBytes in MSB" |
1244 "return my hexBytes in MSB" |
1241 |
1245 |
1242 ^ self digitBytesMSB:true |
1246 ^ self digitBytesMSB |
1243 ! |
1247 ! |
1244 |
1248 |
1245 asByteArrayOfSize:size |
1249 asByteArrayOfSize:size |
1246 "return my hexBytes in MSB, optionally padded at the left with zeros" |
1250 "return my hexBytes in MSB, optionally padded at the left with zeros" |
1247 |
1251 |
1250 repeats := 1000000. |
1254 repeats := 1000000. |
1251 number := 123456789123456789123456789123456789123456789123456789. |
1255 number := 123456789123456789123456789123456789123456789123456789. |
1252 [repeats timesRepeat: (number asByteArrayOfSize: 1024) ] timeToRun. |
1256 [repeats timesRepeat: (number asByteArrayOfSize: 1024) ] timeToRun. |
1253 )))" |
1257 )))" |
1254 |
1258 |
1255 | bytes | |
1259 | bytes bytesSize| |
1256 |
1260 |
1257 bytes := self digitBytesMSB:true. |
1261 bytes := self digitBytesMSB. |
1258 size < bytes size ifTrue: [ |
1262 bytesSize := bytes size. |
|
1263 size < bytesSize ifTrue: [ |
1259 ^ ConversionError raiseRequestWith:self errorString:'number too big for ', size asString |
1264 ^ ConversionError raiseRequestWith:self errorString:'number too big for ', size asString |
1260 ]. |
1265 ]. |
1261 ^ (ByteArray new: (size - bytes size)), bytes |
1266 ^ (ByteArray new:size) |
|
1267 replaceFrom:size-bytesSize+1 to:size with:bytes startingAt:1. |
1262 |
1268 |
1263 " |
1269 " |
1264 123 asByteArrayOfSize:1 #[123] |
1270 123 asByteArrayOfSize:1 #[123] |
1265 123 asByteArrayOfSize:2 #[0 123] |
1271 123 asByteArrayOfSize:2 #[0 123] |
1266 123 asByteArrayOfSize:4 #[0 0 0 123] |
1272 123 asByteArrayOfSize:4 #[0 0 0 123] |
2327 least significant byte is first" |
2333 least significant byte is first" |
2328 |
2334 |
2329 ^ self subclassResponsibility |
2335 ^ self subclassResponsibility |
2330 ! |
2336 ! |
2331 |
2337 |
|
2338 digitBytesMSB |
|
2339 "return a byteArray filled with the receivers bits |
|
2340 (8 bits of the absolute value per element), |
|
2341 most significant byte is first" |
|
2342 |
|
2343 ^ self subclassResponsibility |
|
2344 ! |
|
2345 |
2332 digitBytesMSB:msbFlag |
2346 digitBytesMSB:msbFlag |
2333 "return a byteArray filled with the receivers bits |
2347 "return a byteArray filled with the receivers bits |
2334 (8 bits of the absolute value per element), |
2348 (8 bits of the absolute value per element), |
2335 if msbflag = true, most significant byte is first, |
2349 if msbflag = true, most significant byte is first, |
2336 otherwise least significant byte is first" |
2350 otherwise least significant byte is first" |
2337 |
2351 |
2338 msbFlag ifTrue:[ |
2352 msbFlag ifTrue:[ |
2339 ^ self digitBytes copyReverse. "digitBytes may be shared - reverse a copy!!" |
2353 ^ self digitBytesMSB. |
2340 ]. |
2354 ]. |
2341 ^ self digitBytes |
2355 ^ self digitBytes |
2342 |
2356 |
2343 " |
2357 " |
2344 16r12 digitBytesMSB:true |
2358 16r12 digitBytesMSB:true |
4299 " |
4313 " |
4300 |
4314 |
4301 "Created: / 09-01-2012 / 17:18:06 / cg" |
4315 "Created: / 09-01-2012 / 17:18:06 / cg" |
4302 ! ! |
4316 ! ! |
4303 |
4317 |
|
4318 |
4304 !Integer methodsFor:'special modulu arithmetic'! |
4319 !Integer methodsFor:'special modulu arithmetic'! |
4305 |
4320 |
4306 add_32:anInteger |
4321 add_32:anInteger |
4307 "return a C-semantic 32bit sum of the receiver and the argument. |
4322 "return a C-semantic 32bit sum of the receiver and the argument. |
4308 Both must be either Small- or LargeIntegers. |
4323 Both must be either Small- or LargeIntegers. |
4985 ! ! |
5000 ! ! |
4986 |
5001 |
4987 !Integer class methodsFor:'documentation'! |
5002 !Integer class methodsFor:'documentation'! |
4988 |
5003 |
4989 version |
5004 version |
4990 ^ '$Header: /cvs/stx/stx/libbasic/Integer.st,v 1.283 2013-07-26 11:58:52 cg Exp $' |
5005 ^ '$Header: /cvs/stx/stx/libbasic/Integer.st,v 1.284 2013-07-28 19:35:00 stefan Exp $' |
4991 ! |
5006 ! |
4992 |
5007 |
4993 version_CVS |
5008 version_CVS |
4994 ^ '$Header: /cvs/stx/stx/libbasic/Integer.st,v 1.283 2013-07-26 11:58:52 cg Exp $' |
5009 ^ '$Header: /cvs/stx/stx/libbasic/Integer.st,v 1.284 2013-07-28 19:35:00 stefan Exp $' |
4995 ! ! |
5010 ! ! |
4996 |
5011 |
4997 |
5012 |
4998 Integer initialize! |
5013 Integer initialize! |