RfD: Number Prefixes
  Home FAQ Contact Sign in
comp.lang.forth only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.forth Profile…
 Up
RfD: Number Prefixes         


Author: Anton Ertl
Date: Aug 3, 2007 11:07

Problem

It is often useful to write numbers in other than the current BASE.
Changing BASE to do this is often inconvenient and has lead to
hard-to-find errors.

Solution

The Forth text interpreter should accept numbers like the following ones:

#-12346789. \ decimal double
$-1234cDeF. \ hex double
%%-10101010. \ binary double
'a' \ equivalent to char a or [char] a

(and of course without "." for single-cell and without - for positive
and unsigned numbers; the text interpreter only has to accept
double-cell numbers if the double-cell wordset is present).

Typical usage:
Show full article (1.51Kb)
232 Comments
Re: RfD: Number Prefixes         


Date: Aug 3, 2007 13:11

On Aug 3, 8:07 pm, an...@mips.complang.tuwien.ac.at (Anton Ertl)
wrote:
> Problem
>
> It is often useful to write numbers in other than the current BASE.
> Changing BASE to do this is often inconvenient and has lead to
> hard-to-find errors.

First of all, I would suggest to use & as a "prefix" for octal
numbers.

Second: I dont understand, why it has to be a prefix. I could
perfectly imagine to have multiple such "prefixes" to construct
numbers - eg. to contruct numbers with mixed bases. A number converter
would then (temporarily) change the base at the point where the
"prefix" occurs.

Third: To simplify things, the minus-sign should simply flag that the
result is negative (as . (dot) does with doubles), as long as there
are no digits other than 0 (zero). That means an implementation has
simply to check if temporary convert result is zero and then to accept
the minus.
Show full article (0.99Kb)
no comments
Re: RfD: Number Prefixes         


Date: Aug 3, 2007 13:16

On Aug 3, 10:11 pm, hel...@gmail.com wrote:
> 12-34
means -1234

-Helmar
no comments
Re: RfD: Number Prefixes         


Author: Alex McDonald
Date: Aug 3, 2007 13:56

On Aug 3, 7:07 pm, an...@mips.complang.tuwien.ac.at (Anton Ertl)
wrote:
> Problem
>
> It is often useful to write numbers in other than the current BASE.
> Changing BASE to do this is often inconvenient and has lead to
> hard-to-find errors.
>
> Solution
>
> The Forth text interpreter should accept numbers like the following ones:
>
> #-12346789. \ decimal double
> $-1234cDeF. \ hex double
> %%-10101010. \ binary double
> 'a' \ equivalent to char a or [char] a
>
> (and of course without "." for single-cell and without - for positive
> and unsigned numbers; the text interpreter only has to accept
> double-cell numbers if the double-cell wordset is present). ...
Show full article (7.08Kb)
no comments
Re: RfD: Number Prefixes         


Author: Alex McDonald
Date: Aug 3, 2007 14:05

On Aug 3, 9:11 pm, hel...@gmail.com wrote:
> On Aug 3, 8:07 pm, an...@mips.complang.tuwien.ac.at (Anton Ertl)
> wrote:
>
>> Problem
>
>> It is often useful to write numbers in other than the current BASE.
>> Changing BASE to do this is often inconvenient and has lead to
>> hard-to-find errors.
>
> First of all, I would suggest to use & as a "prefix" for octal
> numbers.
>
> Second: I dont understand, why it has to be a prefix. I could
> perfectly imagine to have multiple such "prefixes" to construct
> numbers - eg. to contruct numbers with mixed bases. A number converter
> would then (temporarily) change the base at the point where the
> "prefix" occurs.
>
> Third: To simplify things, the minus-sign should simply flag that the ...
Show full article (1.22Kb)
no comments
Re: RfD: Number Prefixes         


Date: Aug 3, 2007 14:11

On Aug 3, 11:05 pm, Alex McDonald rivadpm.com> wrote:
> Ouch to 12-43. O-uch ou-ch ouc-h, that hurts, even in base36.

Yes, that's why I did not want to write it. I forgot to remove this
example. That's also why I wrote the converter should check for zero.
I know that you would say "ouch" ;)
> And 1- is not a number.

: 6 ." six" ;

and 6 is no number.

-Helmar
no comments
Re: RfD: Number Prefixes         


Author: Alex McDonald
Date: Aug 3, 2007 14:18

On Aug 3, 10:11 pm, hel...@gmail.com wrote:
> On Aug 3, 11:05 pm, Alex McDonald rivadpm.com> wrote:
>
>> Ouch to 12-43. O-uch ou-ch ouc-h, that hurts, even in base36.
>
> Yes, that's why I did not want to write it. I forgot to remove this
> example. That's also why I wrote the converter should check for zero.
> I know that you would say "ouch" ;)
>
>> And 1- is not a number.
>
> : 6 ." six" ;
>
> and 6 is no number.
>
> -Helmar

I meant that 1- is defined in the standard; it's not the same as -1.
Allowing 0- would simply serve to confuse.
Show full article (0.59Kb)
no comments
Re: RfD: Number Prefixes         


Date: Aug 3, 2007 14:25

On Aug 3, 11:18 pm, Alex McDonald rivadpm.com> wrote:
> On Aug 3, 10:11 pm, hel...@gmail.com wrote:
>
>> On Aug 3, 11:05 pm, Alex McDonald rivadpm.com> wrote:
>
>>> Ouch to 12-43. O-uch ou-ch ouc-h, that hurts, even in base36.
>
>> Yes, that's why I did not want to write it. I forgot to remove this
>> example. That's also why I wrote the converter should check for zero.
>> I know that you would say "ouch" ;)
>
>>> And 1- is not a number.
>
>> : 6 ." six" ;
>
>> and 6 is no number.
>
>> -Helmar
>
> I meant that 1- is defined in the standard; it's not the same as -1. ...
Show full article (1.19Kb)
no comments
Re: RfD: Number Prefixes         


Date: Aug 3, 2007 14:27

On Aug 3, 11:25 pm, hel...@gmail.com wrote:
> '-' Of Result @ Negative? @ abort" sign on wrong place"
'-' Of Result @ Negative? @ or abort" ...

(Today's a bug in my keybord ;) )

-Helmar
no comments
Re: RfD: Number Prefixes         


Author: Coos Haak
Date: Aug 3, 2007 15:11

Op Fri, 03 Aug 2007 13:11:13 -0700 schreef helmwo@gmail.com:
> On Aug 3, 8:07 pm, an...@mips.complang.tuwien.ac.at (Anton Ertl)
> wrote:
>> Problem
>>
>> It is often useful to write numbers in other than the current BASE.
>> Changing BASE to do this is often inconvenient and has lead to
>> hard-to-find errors.
>
> First of all, I would suggest to use & as a "prefix" for octal
> numbers.

Why, who's still using octal in this century? I'm perfecty comfortable with
& as an alternative to CHAR or [CHAR]
> Second: I dont understand, why it has to be a prefix. I could
> perfectly imagine to have multiple such "prefixes" to construct
> numbers - eg. to contruct numbers with mixed bases. A number converter
> would then (temporarily) change the base at the point where the
> "prefix" occurs.

Too complicated, and confusing
Show full article (1.33Kb)
no comments

RELATED THREADS
SubjectArticles qty Group
C-mode blows away may Ctrl-C binding with a prefix -- how to remap prefix?gnu.emacs.help ·
1 2 3 4 5 6 7 8 9