Levente Uzonyi uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-ul.1006.mcz ==================== Summary ==================== Name: Kernel-ul.1006 Author: ul Time: 19 March 2016, 1:28:42.41382 pm UUID: 0883d257-21c1-4bac-bc57-a6cfc1b423e4 Ancestors: Kernel-eem.1005 - 10% faster SmallInteger >> #decimalDigitLength on 64-bit VM - added a comment to SmallInteger >> #numberOfDigitsInBase: - reformatted and tweaked Number >> #raisedToInteger: =============== Diff against Kernel-eem.1005 =============== Item was changed: ----- Method: Number>>raisedToInteger: (in category 'mathematical functions') ----- raisedToInteger: anInteger - "The 0 raisedToInteger: 0 is an special case. In some contexts must be 1 and in others must be handled as an indeterminate form. I take the first context because that's the way that was previously handled. Maybe further discussion is required on this topic." + | bitProbe result | - |bitProbe result| - anInteger negative ifTrue: [^(self raisedToInteger: anInteger negated) reciprocal]. bitProbe := 1 bitShift: anInteger highBit - 1. + result := self class one. + [ + (anInteger bitAnd: bitProbe) > 0 ifTrue: [ result := result * self ]. + (bitProbe := bitProbe bitShift: -1) > 0 ] + whileTrue: [ result := result * result ]. - result := self class one. - [ - (anInteger bitAnd: bitProbe) = 0 ifFalse: [result := result * self]. - bitProbe := bitProbe bitShift: -1. - bitProbe > 0 ] - whileTrue: [result := result * result]. - ^result! Item was changed: ----- Method: SmallInteger>>decimalDigitLength (in category 'printing') ----- decimalDigitLength "Answer the number of digits printed out in base 10. Note that this only works for positive SmallIntegers up to 64-bits." + self < 10000 ifTrue: [ + self < 100 ifTrue: [ + self < 10 ifTrue: [ ^1]. + ^2 ]. + self < 1000 ifTrue: [ ^3 ]. + ^4 ]. + self < 100000000 ifTrue: [ + self < 1000000 ifTrue: [ + self < 100000 ifTrue: [ ^5]. + ^6 ]. + self < 10000000 ifTrue: [ ^7 ]. + ^8 ]. + self < 1000000000000 ifTrue: [ + self < 10000000000 ifTrue: [ + self < 1000000000 ifTrue: [ ^9 ]. + ^10 ]. + self < 100000000000 ifTrue: [ ^11 ]. + ^12 ]. + self < 10000000000000000 ifTrue: [ + self < 100000000000000 ifTrue: [ + self < 10000000000000 ifTrue: [ ^13 ]. + ^14 ]. + self < 1000000000000000 ifTrue: [ ^15 ]. + ^16 ]. + self < 1000000000000000000 ifTrue: [ + self < 100000000000000000 ifTrue: [ ^17 ]. + ^18 ]. + self < 10000000000000000000 ifTrue: [ ^19 ]. + ^20! - ^self < 10000 - ifTrue: - [self < 100 - ifTrue: - [self < 10 ifTrue: [1] ifFalse: [2]] - ifFalse: - [self < 1000 ifTrue: [3] ifFalse: [4]]] - ifFalse: - [self < 100000000 - ifTrue: - [self < 1000000 - ifTrue: [self < 100000 ifTrue: [5] ifFalse: [6]] - ifFalse: [self < 10000000 ifTrue: [7] ifFalse: [8]]] - ifFalse: - [self < 1000000000000 - ifTrue: - [self < 10000000000 - ifTrue: [self < 1000000000 ifTrue: [9] ifFalse: [10]] - ifFalse: [self < 100000000000 ifTrue: [11] ifFalse: [12]]] - ifFalse: - [self < 10000000000000000 - ifTrue: - [self < 100000000000000 - ifTrue: [self < 10000000000000 ifTrue: [13] ifFalse: [14]] - ifFalse: [self < 1000000000000000 ifTrue: [15] ifFalse: [16]]] - ifFalse: - [self < 1000000000000000000 - ifTrue: [self < 100000000000000000 ifTrue: [17] ifFalse: [18]] - ifFalse: [self < 10000000000000000000 ifTrue: [19] ifFalse: [20]]]]]]! Item was changed: ----- Method: SmallInteger>>numberOfDigitsInBase: (in category 'printing') ----- numberOfDigitsInBase: b "Return how many digits are necessary to print this number in base b. Mostly same as super but an optimized version for base 10 case" b = 10 ifFalse: [^super numberOfDigitsInBase: b]. + self < 0 ifTrue: [^self negated numberOfDigitsInBase: b]. "We can't use #decimalDigitLength here, because the receiver might be SmallInteger minVal." - self < 0 ifTrue: [^self negated numberOfDigitsInBase: b]. ^self decimalDigitLength! |
Free forum by Nabble | Edit this page |