FIF. Another FORTH.

Discussion about ZX80 / ZX81 Software
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: FIF. Another FORTH.

Post by Moggy »

A useful double number operator to accompany D+ usually missing from older Forths is D-
I have operators for D* and D/ too which I will test to see if they will compile.

: D- DNEGATE D+ ;
Last edited by Moggy on Fri Mar 26, 2021 11:49 pm, edited 3 times in total.
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: FIF. Another FORTH.

Post by Moggy »

D/ also seems to compile nicely.

: D/ M/MOD ROT DROP ;

Example.
12.000 D/ 7 answer 1.714 (to 3 places)

Enter

12000. 7 D/ ZZZ (number format to 3 places from earlier post)

1.714 OK

Routine courtesy of Kmurta.
Last edited by Moggy on Sat Mar 27, 2021 11:34 pm, edited 1 time in total.
roganjosh
Posts: 100
Joined: Thu Jun 14, 2018 12:59 pm

Re: FIF. Another FORTH.

Post by roganjosh »

Splendid to hear about the full speed typing. Wish I could say it was planned.
Ta for the D- and D/ definitions. They were intentionally left out because they're not in the 79 standard and I was trying to be parsimonious with RAM at the time. However I do want to hear peoples' opinions as to whether they found particular words so commonly useful that it would be tedious to have to load them from screens at every session. They can certainly go in.

It struck me later last night why I only allowed a terminating '.' to define double precision numbers. It was in case I ever got round to writing a floating point library. Diehard Forth programmers are often of the opinion that if it can't be done in integer then it's not worth doing; also it wouldn't be high on my list of things to do. Nevertheless, at the time, I thought I'd leave the possibility open. Have others been able to marry the two (FP and wandering '.') and, if so, how? I suppose you could insist on FP numbers being defined with a '.' and an exponent.

Don't get me wrong, I'll certainly have a look/think. I'm just curious as it's something I've not thought of before..


Edit:
Ah, I've done some digging and there would be no conflict with FP if judicious use is made of exponents and signs.
I'm a bit confused about the heritage of 'D/' though. It doesn't appear in the 83 Standard either (unlike 'D-' which appears in the extensions).
From your definition it looks like its expected behaviour is:

D/ (ud1\u2 ... ud3)
Uses/Leaves 3 2
Leaves, as the double number ud3 the quotient from the
division of the double number dividend ud1 by the single
number divisor u2. All are unsigned integers.

Was that the required behaviour?

Alan
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: FIF. Another FORTH.

Post by Moggy »

Hi Alan.

In reference to the point terminator for double numbers I wasn't meaning lets have a FP definition for the point only a VISUAL look to how the numbers are input.

I work in integer with no requirement for FP because getting places after the point is so easy to do after scaling then displaying using standard F79 number formatting,to me this is as easy as breathing.
As far as I understand it in most Forths the point can be placed ANYWHERE in the number and all it denotes is that the number is a double not a decimal, all I'm saying is that being the case it is far easier on the eye to enter 12.123 rather than 12123. and give the impression that you are working in decimals if you follow what I'm saying.

Where the point is placed is irreverential to Forth as I say it just knows "double number follows" then relies on Forths number formatting to make the out put look decimally correct, I'm only suggesting that if like other Forths the point can go anywhere in a double integer when inputting then it looks ascetically better whilst still working in integer.

As for the double operators I personally find them very useful as I no longer have to mess around with the likes ofM/MOD U/MOD in their various combinations to get the results I'm after.
I do have one forD* but find it a bit cumbersome in its structure as it involves invoking 4 variables a few U* DROP's etc and have yet to try it with FIF79.

Kmurta has a beta of his Toddy forth with all double operators compiled so when he decides to release it it might be worth looking at for ideas of your own.

As for the D/ this is one of Kmurta's compilations kindly done for myself to get a SQRT program to work correctly and all I know is that it works for my other computations too so have left it in.
The implementation he uses currently in beta is ud1 /d2...ud3 if I read it correctly and is much more tidier than some of the other / operators.

Please take all my comments as honest constructivism as when it comes to Forth I want all those who have the Latin to create such things to have the best possible outcome for their creations so I comment as honestly as I can as an end user. I was the biggest critic of Toddy Forth at one time pointing out what I thought was it's shortcomings,perhaps too cuttingly at times and have since learned to curb my passions in this regard. Kmurta took all this on the chin and over time has now created what in my opinion is possibly the finest Forths I know of for the 81 ZXpand combination.

I only mention Toddy as a yardstick for which you might want to tailor FIF81'

You mention memory constraints, well at this point Toddy(beta) has full double operators,SQRT function plus what looks to me like some 64 bit gubbins, a few more bells and whistles,FP to be implemented and still manages just over 9k memory left to play with.

If your wish is to make an honest F79 (which I sincerely hope you do as I would love to have an historically correct Forth if only to make Brodies bloody book readable! :lol: ) then having less operators than those listed above, 10k + memory to play with should be do-able.

AAAANNND BREATHHHH!! :lol:

I wish you well in this,Alan and will support all your endeavours in this exciting little project.
Last edited by Moggy on Sat Mar 27, 2021 8:55 pm, edited 1 time in total.
roganjosh
Posts: 100
Joined: Thu Jun 14, 2018 12:59 pm

Re: FIF. Another FORTH.

Post by roganjosh »

Hi Moggy,

Thanks. I had understood your full-stop thing perfectly though. I was just musing how people had squared it with any FP implementations they had done, not that I was going to do any FP myself in the near future. As I said, I found out so that problem is solved. There is no fundamental incompatibility. The double precision dot thing, though conceptually easy, doesn't look to be a tidy thing as far as coding is concerned. I installed gforth under linux this afternoon and that doesn't allow any dots at the start though it's perfectly happy if you sprinkle multiple ones liberally elsewhere. I haven't yet looked at how other Forths handle such boundary cases. I'm still thinking about the best way to recode the numeric input routines to cater for them. I'll post when it's done.

My point about D/ was that I was expecting it to be a signed operation whereas the definition you gave looked more like a UD/.

Many thanks for your input. It has been, and will continue to be welcome.

Alan
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: FIF. Another FORTH.

Post by Moggy »

Hi Alan.

Just checked up on that D/ operator and apparently it's : D/ (ud1 u2 -- ud3) UD/MOD ROT DROP ;

Either way it works seemingly well in FIF81 using M/MOD for UD/MOD
roganjosh
Posts: 100
Joined: Thu Jun 14, 2018 12:59 pm

Re: FIF. Another FORTH.

Post by roganjosh »

Moggy wrote: Sat Mar 27, 2021 8:57 pm Hi Alan.

Just checked up on that D/ operator and apparently it's : D/ (ud1 u2 -- ud3) UD/MOD ROT DROP ;

Either way it works seemingly well in FIF81 using M/MOD for UD/MOD
Hi Moggy,

Thanks, good to know. That still leaves my question open though. Probably my fault for not being clear enough. Here's another way of framing it: "As it deals exclusively with unsigned numbers why is the word called 'D/' when it probably ought to have been called something like 'UD/' ?"

The double precision thing seems to be working now. I'll just test it a bit more and then post another version.

Alan
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: FIF. Another FORTH.

Post by Moggy »

Because it was only meant to solve a one off problem in a program so I could type it as it is in the source material D/ as opposed to UD/ which as you say is more correct but being an old fogy I get easily confused and needed a simple looking solution and it wasn't meant for open consumption,written as D/ only for myself and posted just as an example.

The D/ used by Kmurta in his beta Toddy is different and correctly compiled.

Also Alan, I tried the PSAVE in the emulator SZ81 and it works just fine so for a giggle tried it in the ZXpand which went through the motions of saving, lights flashing etc,but to nil event. I did notice however that the emulator saved file uses " _ " as the file name which is a character not allowed on the ZXpand so I suspect that if the file name were different ZXpand load/save would be possible at this stage.

Your thoughts?
roganjosh
Posts: 100
Joined: Thu Jun 14, 2018 12:59 pm

Re: FIF. Another FORTH.

Post by roganjosh »

Moggy wrote: Sat Mar 27, 2021 9:58 pm
Also Alan, I tried the PSAVE in the emulator SZ81 and it works just fine so for a giggle tried it in the ZXpand which went through the motions of saving, lights flashing etc,but to nil event. I did notice however that the emulator saved file uses " _ " as the file name which is a character not allowed on the ZXpand so I suspect that if the file name were different ZXpand load/save would be possible at this stage.

Your thoughts?
Hi Moggy,

That's a bit curious and, at this time of night I generally have few things which can loosely be classified as thoughts. With the detective work it might well be a case of "rem acu tetigisti" (you did mention those who speak Latin in an earlier post). I'll take a look.

Anyway, I've put a new version up. Having looked at the gforth documentation, throwing an error if the '.' is the first character of the double number looks like the correct behaviour, but having multiple dots isn't. So that's how I've coded it - only one dot per number. If that turns out to be wrong then it's easily changed.

Ta for the report.

Alan
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: FIF. Another FORTH.

Post by Moggy »

Many thanks Alan.

Here's that operator for D* I mentioned.


0 VARIABLE A
0 VARIABLE B
0 VARIABLE C
0 VARIABLE D

: D* A ! B ! C ! D !

D @ B @ U*

D @ A @ U* DROP +

C @ B @ U* DROP + ;

Example.


6000. 12000. D* D. 72000000


Taken from.

The complete Forth.

By Alan Winfield.



A bit convoluted I think but works well on 2 doubles.
Post Reply