durexforth icon indicating copy to clipboard operation
durexforth copied to clipboard

Double literals, M*/

Open burnsauce opened this issue 3 years ago • 4 comments

This patch does 2 things:

  1. Implement M*/
  2. Implement double literals with a trailing period

Discussion of this feature at #433

M*/ is required to achieve the double literal because base conversion must use doubles as input to multiplication, and this is the only forth operator to do this. Internally it's a 32*32=64 bit multiplier with a 48/16=32 bit divider.

There is no performance impact to the math.asm changes: ud/mod's changes come out in the wash when integrated with ut/mod, an unlisted function that accepts a triple (48-bit) dividend and a 16-bit divisor. It is effectively the exact same routine as before, as the cascading divison required a leading 0 to divide the top word anyways.

READ_NUMBER is slower, owing to the 32-bit multiplication, but now able to return a double.

The code is obviously larger.

This commit updates the changelog and has cleared include test.

burnsauce avatar Jan 14 '22 07:01 burnsauce

Hi! Just wanted to say, sorry I haven't had the time to review yet! It's been a busy start of the year, and I haven't had much spare time or brain cycles. I will get to it when I can give it the attention it deserves.

jkotlinski avatar Jan 23 '22 20:01 jkotlinski

Hi! Just wanted to say, sorry I haven't had the time to review yet! It's been a busy start of the year, and I haven't had much spare time or brain cycles. I will get to it when I can give it the attention it deserves.

No problem. I update the related issue with my new doubt about use of doubles for fixed point maths. The single-precision divisor of M*/ seems to be a severely limiting factor.

As fixed-point was going to be my primary use of doubles, I now doubt the utility of this patch.

I'll keep thinking about it and update this patch to my latest, but there's no imperative to merge this.

burnsauce avatar Jan 24 '22 01:01 burnsauce

OK, I will keep it open for further pondering.

jkotlinski avatar Aug 07 '22 21:08 jkotlinski

Did you think further about this topic? I have been undecided, if I think this functionality would be a valuable addition or not.

To get some bearings, I did a quick investigation on how other C64 Forths do. It seems double literals are near-universally supported, while M*/ is less common, but implemented by some high-quality Forths (e.g. Blazin` Forth).

Personally I do not care so much about either, as I prefer to do any serious number crunching on the PC, and then lift the results to C64. But I think it would be fair to argue that double literals is something one could expect from a 16-bit Forth. As such, I am open for this idea, if anyone wants it added.

jkotlinski avatar Aug 27 '22 22:08 jkotlinski