equal
deleted
inserted
replaced
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. |
1661 since the digits are stored as absolute value. |
1665 since the digits are stored as absolute value. |
1662 Q: is this specified in a language standard ?" |
1666 Q: is this specified in a language standard ?" |
1663 |
1667 |
1664 "/ ^ -1 - self |
1668 "/ ^ -1 - self |
1665 |
1669 |
1666 |n "{ Class: SmallInteger }" |
1670 |n "{ Class: SmallInteger }" |
1667 result byte| |
1671 byte "{ Class: SmallInteger }" |
|
1672 result| |
1668 |
1673 |
1669 n := self digitLength. |
1674 n := self digitLength. |
1670 result := self class basicNew numberOfDigits:n. |
1675 result := self class basicNew numberOfDigits:n. |
1671 |
1676 |
1672 1 to:n do:[:index | |
1677 1 to:n do:[:index | |
1673 byte := self digitAt:index. |
1678 byte := self digitAt:index. |
1674 result digitAt:index put:(byte bitInvert bitAnd:16rFF). |
1679 byte := byte bitInvert bitAnd:16rFF. |
1675 ]. |
1680 result digitAt:index put:byte. |
1676 (byte == 255 or:[n <= SmallInteger maxBytes]) ifTrue:[ |
1681 ]. |
|
1682 (byte == 0 or:[n <= SmallInteger maxBytes]) ifTrue:[ |
|
1683 "if last byte is zero we can normalize" |
1677 ^ result compressed |
1684 ^ result compressed |
1678 ]. |
1685 ]. |
1679 ^ result |
1686 ^ result |
1680 |
1687 |
1681 " |
1688 " |
|
1689 16rff bitInvert bitAnd:16rff |
1682 16rffffffff bitInvert |
1690 16rffffffff bitInvert |
1683 16rff00ff00 bitInvert hexPrintString |
1691 16rff00ff00 bitInvert hexPrintString |
1684 " |
1692 " |
1685 ! |
1693 ! |
1686 |
1694 |
4323 " |
4331 " |
4324 |
4332 |
4325 "Created: / 09-01-2012 / 17:18:06 / cg" |
4333 "Created: / 09-01-2012 / 17:18:06 / cg" |
4326 ! ! |
4334 ! ! |
4327 |
4335 |
|
4336 |
4328 !Integer methodsFor:'special modulu arithmetic'! |
4337 !Integer methodsFor:'special modulu arithmetic'! |
4329 |
4338 |
4330 add_32:anInteger |
4339 add_32:anInteger |
4331 "return a C-semantic 32bit sum of the receiver and the argument. |
4340 "return a C-semantic 32bit sum of the receiver and the argument. |
4332 Both must be either Small- or LargeIntegers. |
4341 Both must be either Small- or LargeIntegers. |
4940 |
4949 |
4941 |e t cnt| |
4950 |e t cnt| |
4942 |
4951 |
4943 "throw off low nbits(modulus)" |
4952 "throw off low nbits(modulus)" |
4944 |
4953 |
4945 e := (aNumber bitShift:shift). |
4954 e := aNumber bitShift:shift. |
4946 e := e * reciprocal. |
4955 e := e * reciprocal. |
4947 e := (e bitShift:shift). |
4956 e := e bitShift:shift. |
4948 e := e * modulus. |
4957 e := e * modulus. |
4949 e := aNumber - e. |
4958 e := aNumber - e. |
4950 |
4959 |
4951 "this subtract is done max 2 times" |
4960 "this subtract is done max 2 times" |
4952 cnt := 2. |
4961 cnt := 2. |
4977 "SLOW (using standard \\ operation): |
4986 "SLOW (using standard \\ operation): |
4978 |m| |
4987 |m| |
4979 |
4988 |
4980 m := 123456789901398721398721931729371293712943794254034548369328469438562948623498659238469234659823469823658423659823658. |
4989 m := 123456789901398721398721931729371293712943794254034548369328469438562948623498659238469234659823469823658423659823658. |
4981 Time millisecondsToRun:[ |
4990 Time millisecondsToRun:[ |
4982 1000 timesRepeat:[ |
4991 100000 timesRepeat:[ |
4983 874928459437598375937451931729371293712943794254034548369328469438562948623498659238469234659823469823658423659823658 \\ m |
4992 874928459437598375937451931729371293712943794254034548369328469438562948623498659238469234659823469823658423659823658 \\ m |
4984 ] |
4993 ] |
4985 ] |
4994 ] |
4986 " |
4995 " |
4987 |
4996 |
4988 "fast (using moduloNumber with almost same-sized dividend and divisor): |
4997 "fast (using moduloNumber with almost same-sized dividend and divisor): |
4989 |m| |
4998 |m| |
4990 |
4999 |
4991 m := self new modulus:123456789901398721398721931729371293712943794254034548369328469438562948623498659238469234659823469823658423659823658. |
5000 m := self new modulus:123456789901398721398721931729371293712943794254034548369328469438562948623498659238469234659823469823658423659823658. |
4992 Time millisecondsToRun:[ |
5001 Time millisecondsToRun:[ |
4993 1000 timesRepeat:[ |
5002 100000 timesRepeat:[ |
4994 m modulusOf:874928459437598375937451931729371293712943794254034548369328469438562948623498659238469234659823469823658423659823658. |
5003 m modulusOf:874928459437598375937451931729371293712943794254034548369328469438562948623498659238469234659823469823658423659823658. |
4995 ] |
5004 ] |
4996 ] |
5005 ] |
4997 " |
5006 " |
4998 |
5007 |
5009 ! ! |
5018 ! ! |
5010 |
5019 |
5011 !Integer class methodsFor:'documentation'! |
5020 !Integer class methodsFor:'documentation'! |
5012 |
5021 |
5013 version |
5022 version |
5014 ^ '$Header: /cvs/stx/stx/libbasic/Integer.st,v 1.287 2013-09-30 10:44:21 cg Exp $' |
5023 ^ '$Header: /cvs/stx/stx/libbasic/Integer.st,v 1.288 2013-12-02 20:00:24 stefan Exp $' |
5015 ! |
5024 ! |
5016 |
5025 |
5017 version_CVS |
5026 version_CVS |
5018 ^ '$Header: /cvs/stx/stx/libbasic/Integer.st,v 1.287 2013-09-30 10:44:21 cg Exp $' |
5027 ^ '$Header: /cvs/stx/stx/libbasic/Integer.st,v 1.288 2013-12-02 20:00:24 stefan Exp $' |
5019 ! ! |
5028 ! ! |
5020 |
5029 |
5021 |
5030 |
5022 Integer initialize! |
5031 Integer initialize! |