[Pharo-project] digitAt: issue
Sven Van Caekenberghe
sven at beta9.be
Mon May 2 11:31:42 CEST 2011
On 02 May 2011, at 11:13, Bernat Romagosa wrote:
> Hi, try to run the following:
> (2 raisedTo: 100000) digitAt: 1
> The expected result (if I understood what digitAt: should return) is 9, but the message returns 0 instead. In fact, it returns 0 for any index.
> Is this a bug or am I missunderstanding how digitAt: should work?
> Bernat Romagosa.
> p.s. My config is Pharo 1.2 with a 'Croquet Closure Cog VM [CoInterpreter VMMaker-oscog.51]' on Debian Lenny.
2 raisedTo: 32
#digitAt: for digits 1 to 4 returns 0, 5 return 1.
From the comments you can see that the number is looked at in base 256.
The above number thus has 5 digits in this base, four are zero and the highest one is one.
Furthermore, the first digit is the lowest one.
If you inspect the number it might become clearer.
Any #digitAt: has to depend on the base you use to represent the number, this one doesn't, so it seems to be useful only to return internal parts of a number.
More information about the Pharo-project