[Pharo-project] digitAt: issue

Bernat Romagosa tibabenfortlapalanca at gmail.com
Mon May 2 15:36:46 CEST 2011


Yup, it seems to me like a horrible name too, especially considering that
bitAt: already exists :)

2011/5/2 Camillo Bruni <camillo.bruni at inria.fr>

> DigitAt: is a horrible name then, should rather be bitAt:.
>
> the digitAt: implementation you're looking for:
>
> ^ self // (10 raisedTo: index - 1) \\ 10
>
> thats quite short :)
>
> On 2011-05-02, at 11:35, Bernat Romagosa wrote:
>
> Ouch, understood!
>
> Then what would be the proper way to address a decimal digit in a number? I
> can only think of (bigNumber asString at: index) asNumber, which is...
> awful.
>
> 2011/5/2 Sven Van Caekenberghe <sven at beta9.be>
>
>> Bernat,
>>
>> 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?
>> >
>> > Cheers,
>> >
>> > Bernat Romagosa.
>> >
>> > p.s. My config is Pharo 1.2 with a 'Croquet Closure Cog VM
>> [CoInterpreter VMMaker-oscog.51]' on Debian Lenny.
>>
>> Consider,
>>
>> 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.
>>
>> HTH,
>>
>> Sven
>>
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gforge.inria.fr/pipermail/pharo-project/attachments/20110502/9345e233/attachment.htm>


More information about the Pharo-project mailing list