From: Evertjan. on
Stefan Weiss wrote on 31 mei 2010 in comp.lang.javascript:

> In a unary system it's more usual to count like this:
>
> 1
> 11
> 111
> 1111
>
> Not all values can be expressed this way (for example, 0 or 1.05), but
> at least you get more values that just the zero.

I do not agree in the sense of radixed position dependent strings.

You are mixing position dependent and position independent notation,
and not comparing radix notations.

Your unary system is not based on the extrapolation of such position
dependent numeric string notation.
You even erroneously introduce a position by your right justification.
In your system the zero is an empty string, btw.

Hebrew numbers, while having characters for 1..9 10 20 30 etc, is also
totally position independent, while Latin I II III IV is semi-dependent.
In such systems the zero cannot exist for logical reasons.

So I hold that "radix 1" notation only can specify the zero value, since
that is there only character available, even though a theoretical position
notation exists.

The "radix 0" notation is even more esoteric, as all positions can only be
empty. This does not mean that an empty string is zero, btw.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
From: Stefan Weiss on
On 31/05/10 13:50, Evertjan. wrote:
> Stefan Weiss wrote on 31 mei 2010 in comp.lang.javascript:
>
>> In a unary system it's more usual to count like this:
>>
>> 1
>> 11
>> 111
>> 1111
>>
>> Not all values can be expressed this way (for example, 0 or 1.05), but
>> at least you get more values that just the zero.
>
> I do not agree in the sense of radixed position dependent strings.
>
> You are mixing position dependent and position independent notation,
> and not comparing radix notations.

It was not meant to be an extension of the radix notation; I only said
it was a more usual notation for systems with only one symbol.

> Your unary system is not based on the extrapolation of such position
> dependent numeric string notation.
> You even erroneously introduce a position by your right justification.
> In your system the zero is an empty string, btw.

I never mentioned strings - the concept of an empty string doesn't make
sense on paper, or on the wall of a prison cell.
If the unary notation I used is position independent, how can right or
left justification be an error?

> The "radix 0" notation is even more esoteric, as all positions can only be
> empty. This does not mean that an empty string is zero, btw.

Right, and now let's try fractional radices!


--
stefan
From: Evertjan. on
Stefan Weiss wrote on 31 mei 2010 in comp.lang.javascript:

> I never mentioned strings

Implicitly, the notation of a number in a certain radix MUST BE in a
string.

> - the concept of an empty string doesn't
> make sense on paper, or on the wall of a prison cell.

Oh, but it does, OT as we are talking Javascript number values.

The prisoner has no dilemma in carving the first vertical stroke ony after
his first day in his cell. Thae absense of that stroke is a fair definition
of zero completed days.

> If the unary notation I used is position independent, how can right or
> left justification be an error?

You sowed a right justification, implying there rightmost value to be the
first, either in error, or, if you deny that, in falsehood?


>> The "radix 0" notation is even more esoteric, as all positions can
>> only be empty. This does not mean that an empty string is zero, btw.
>
> Right, and now let's try fractional radices!

RIGHT, then we are LEFT with far more interesting negative radices.

Would they count as uprooted free radicals,
the oxigen of string notation of numbers?

Or is this only string theory?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
From: Ry Nohryb on
On May 31, 1:29 pm, "Evertjan." <exjxw.hannivo...(a)interxnl.net> wrote:
>
> This test is not enough now, meseems:
>
> a = '12345abc.5def'
> document.write((a.toFP(10)) // 12345.0005
>
> use:
>
> var re = base>10 ?'a-'+String.fromCharCode(86+base) :'';
> re = new RegExp('[^0-9'+re+'\.+-]','i');
> if (re.test(this)) return NaN;
>
> and add:
>
> if (/[+-]/.test(this.substr(1))) return NaN; //+- must be in position 0
> if (this.replace(/[^\.]+/g,'').length>1) return NaN; // count of . <=1

Well, yes, the inputs ought to be validated. Both the base parameter
and the 'this' string.

Funny thing is that once you add the -ugly- regExp to test the
structure and its contents, it's easy to use it to capture the
validated parts, and then the rest becomes even simpler than before
( ~8 LOC ):

String.prototype.toFP= function (base, n, r, w, div) {
//20100531 by jorge(a)jorgechamorro.com

/* check that base is in range and an integer */
if ((base < 2) || (base > 36) || (base % 1)) return NaN;

/* get the digits that are valid for this base */
validDigits= "0123456789abcdefghijklmnopqrstuvwxyz".substr(0, base);

/* validate structure and contents of the input str : */
/* ^ (optional) whitespace + (optional) a single char [-+] */
/* + (non-optional) 1 or more validDigits + (optional) a point */
/* + (optional) more validDigits + (optional) whitespace $ */
n= "^\\s{0,}([-+]{0,1})(["+ validDigits+ "]{1,})[.]{0,1}(["+
validDigits+ "]{0,})\\s{0,}$";

/* exec n on 'this' now, case-insensitively, and reuse n*/
if (!(n= new RegExp(n, "i").exec(this))) return NaN;

/* got captured : */
/* n[1]= sign, n[2]=integer part, n[3]= fractional part */

if (isFinite(r= parseInt(n[2], base)) && (w= n[3].length)) {
/* trim until div is finite */
while (!isFinite(div= Math.pow(base, w))) w--;
r+= parseInt(n[3].substr(0, w), base)/ div;
}

/* sign is one of "1" or "+1" or "-1" */
return (n[1]+ "1")* r;
};

--
Jorge.

From: Evertjan. on
Ry Nohryb wrote on 31 mei 2010 in comp.lang.javascript:

> /* get the digits that are valid for this base */
> validDigits= "0123456789abcdefghijklmnopqrstuvwxyz".substr(0, base);

nice!

> /* validate structure and contents of the input str : */
> /* ^ (optional) whitespace + (optional) a single char [-+] */
> /* + (non-optional) 1 or more validDigits + (optional) a point */
> /* + (optional) more validDigits + (optional) whitespace $ */
> n= "^\\s{0,}([-+]{0,1})(["+ validDigits+ "]{1,})[.]{0,1}(["+
> validDigits+ "]{0,})\\s{0,}$";

This would fail for 'pointfractions', like ".56ab" and "-.2"

In short:

n='^\\s*([-+]?)(['+validDigits+']+)\\.?(['+validDigits+']?)\\s*$';


However, to allow for such pointfractions would need something like this:

n1='^\\s*([-+]?)(['+validDigits+']+)\\.?(['+validDigits+']?)\\s*$';
n2='^\\s*([-+]?)()\\.(['+validDigits+']?)\\s*$';

n = n1 + '|' + n2

or

n1 = '^\\s*([-+]?)'
n2a = '(['+validDigits+']+)\\.?'
n2b = '()\\.'
n3 = '(['+validDigits+']?)\\s*$';

n = n1 + '(?:' + n2a + '|' + n2b + ')' + n3

not tested.


> /* exec n on 'this' now, case-insensitively, and reuse n*/
> if (!(n= new RegExp(n, "i").exec(this))) return NaN;

> /* got captured : */
> /* n[1]= sign, n[2]=integer part, n[3]= fractional part */




--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)