Is the world coming to an end?

Nick Sabalausky a at a.a
Fri Apr 8 13:01:08 PDT 2011


"Michel Fortin" <michel.fortin at michelf.com> wrote in message 
news:inn4bp$57s$1 at digitalmars.com...
> On 2011-04-08 07:03:23 -0400, spir <denis.spir at gmail.com> said:
>
>> On 04/08/2011 07:25 AM, Nick Sabalausky wrote:
>>> I want base PI literals :)
>>>
>>> Yum.
>>
>> I want base 1 literals
>>
>> Denis
>
> Like this?
>
> assert(0i == 0)
> assert(0i0 == 1)
> assert(0i00 == 2)
> assert(0i000 == 3)
> assert(0i0000000000_0000000000_0000000000_00 == 32)
>

Pardon my geekdom, but it would probably have to be:

assert(0i == 0)
assert(0i1 == 1)
assert(0i11 == 2)
assert(0i111 == 3)
assert(0i1111111111_1111111111_1111111111_11 == 32)


In general, number bases work like this:

Assuming i=0 is the right-most digit:
(digits.length (SIGMA) i=0) digit[i] * (base^^i)

Or in less mathy notation:

uint[] digits = [...blah...]; // digits[0] is the right-most digit
auto finalValue = 0;
foreach(i; 0..digits.length)
    finalValue += digits[i] * (base^^i);

So using 0 as the only digit in base 1 would result in all numbers being 
equal to 0. But using 1 as the only digit would work.






More information about the Digitalmars-d mailing list