Mathieu Carbou on Fri, 19 Oct 2012 17:08:09 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: digits(0)


Actually I was much more expecting to have the base b digits for each
numbers. I.e. in base 2:

0
1
10
11
...

It is like permutations: there are from 1 to 10 and not from 0 to 9 in
base 10.

As a general guideline, as I see, it means in PARI it is better to
consider 0 as a special case and to have our functions usually based
from 1 (like indexes in PARI) and not from 0 (as other languages) ?

mathieu.


On 19-Oct-2012 11:01, Bill Allombert wrote:
> On Fri, Oct 19, 2012 at 10:46:27AM -0400, Mathieu Carbou wrote:
>> Hello,
>>
>> I was coding something relative to digits in base 2 and my code crashed
>> when the number reached 0 because
>>
>> digits(0, 2) = []
>> digits(0, 10) = []
>>
>> Whereas digits(1,2) = [1]
>>
>> I was expecting
>>
>> digits(0, 2) = [0]
>> digits(0, 10) = [0]
>>
>> Why 0 does not deserve to be a digit ? In base 2, or b the first
> Because the traditional policy is to delete leading zeros, so the number of digits
> of 0 is 0, not 1.
>
>> bit/digit is 1*b^0 or 0*b^0 so why it is not in the resulting vector  ?
> Do you mean that digits(1,2) should be [0,1] because 1 is 0*b^1+1*b^0 ?
>
> Cheers,
> Bill.
>
>


-- 

Mathieu Carbou
Cell: 514-660-4287