Negative number syntax

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Negative number syntax

Sven Van Caekenberghe-2
Hi,

I came across the following quirk that surprised me.

Positive number in a arbitrary radix

  16rA = 10

Same number but negative

  -16rA = -10

I guess, we all know that.

However, the following is also possible

  16r-A = -10

I did not know that, but OK.

But what about this one ?

  -16r-A = 10

I understand that the double negation is positive again,
but do we really want to support such a syntax ?

Sven


Reply | Threaded
Open this post in threaded view
|

Re: Negative number syntax

ducasse


> On 15 Jan 2020, at 14:30, Sven Van Caekenberghe <[hidden email]> wrote:
>
> Hi,
>
> I came across the following quirk that surprised me.
>
> Positive number in a arbitrary radix
>
> 16rA = 10
>
> Same number but negative
>
> -16rA = -10
>
> I guess, we all know that.
>
> However, the following is also possible
>
> 16r-A = -10

I would not support this one either
>
> I did not know that, but OK.
>
> But what about this one ?
>
> -16r-A = 10
>
> I understand that the double negation is positive again,
> but do we really want to support such a syntax ?

I would not

>
> Sven
>
>




Reply | Threaded
Open this post in threaded view
|

Re: Negative number syntax

Sven Van Caekenberghe-2
For the record, should we want to remove the option of having a (possible second) minus sign after the radix specification, the expression

 self peekSignIsMinus ifTrue: [ neg := neg not ].

should be removed from NumberParser>>#nextNumber and #nextInteger

But I haven't tested this.

Some unit tests might fail since this 'feature' seems to be supported explicitly.

> On 15 Jan 2020, at 17:38, ducasse <[hidden email]> wrote:
>
>
>
>> On 15 Jan 2020, at 14:30, Sven Van Caekenberghe <[hidden email]> wrote:
>>
>> Hi,
>>
>> I came across the following quirk that surprised me.
>>
>> Positive number in a arbitrary radix
>>
>> 16rA = 10
>>
>> Same number but negative
>>
>> -16rA = -10
>>
>> I guess, we all know that.
>>
>> However, the following is also possible
>>
>> 16r-A = -10
>
> I would not support this one either
>>
>> I did not know that, but OK.
>>
>> But what about this one ?
>>
>> -16r-A = 10
>>
>> I understand that the double negation is positive again,
>> but do we really want to support such a syntax ?
>
> I would not
>
>>
>> Sven