[Pkg] The Trunk: Kernel-nice.1107.mcz
commits at source.squeak.org
commits at source.squeak.org
Thu Jun 1 22:13:41 UTC 2017
Nicolas Cellier uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-nice.1107.mcz
==================== Summary ====================
Name: Kernel-nice.1107
Author: nice
Time: 2 June 2017, 12:13:19.450751 am
UUID: 597f9f85-fe7b-430a-8ba2-1dd548dc246f
Ancestors: Kernel-eem.1106
Correct digitLength for negative SmallInteger
The length was overestimated for some numbers, for example
self assert: -16rFF01 digitLength = 2.
With old code it would answer 3.
Indeed, the binary representation is 16r...FFFFFF00FF
After shifting once, we got 16r....FFFFFF00, that is -256 and we shifted yet another time.
digitLength works on magnitude (like LargeInteger) so we have to take absolute value, but care of SmallInteger minVal abs which is a LargePositiveInteger with same trick as digitAt:
=============== Diff against Kernel-eem.1106 ===============
Item was changed:
----- Method: SmallInteger>>digitLength (in category 'system primitives') -----
digitLength
"Answer the number of indexable fields in the receiver. This value is the
same as the largest legal subscript. Included so that a SmallInteger can
behave like a LargePositiveInteger or LargeNegativeInteger."
| value length |
length := 1.
+ (value := self) < -255
- value := self.
- value >= 0
ifTrue:
+ [length := 2.
+ value := (-256 - self bitShift: -8) + 1 "carefully negate SmallInteger minVal"].
+ [value > 255] whileTrue:
+ [value := value bitShift: -8.
+ length := length + 1].
- [[value > 255] whileTrue:
- [value := value bitShift: -8.
- length := length + 1]]
- ifFalse:
- [[value < -255] whileTrue:
- [value := value bitShift: -8.
- length := length + 1]].
^length!
More information about the Packages
mailing list