Re: [colorforth] Euler Project Problems.
- Subject: Re: [colorforth] Euler Project Problems.
- From: Gwenhwyfaer <gwenhwyfaer@xxxxxxxxx>
- Date: Sat, 10 May 2008 04:21:34 +0100
On 09/05/2008, Ray St. Marie <ray.stmarie@xxxxxxxxx> wrote:
> I've spent a day trying to figure out how I will implement larger then
> 32 bit ( 27 really) numbers in colorforth for Project Euler Problem 3.
>
> Find the Greatest Prime Factor of 600851475143.
That number looks as though it'd fit into a long float without any
loss of precision. So I'd say it's probably worth adding some words to
do basic floating point maths. Fortunately for colorForth, the x86 FPU
is organised around an 8-deep stack, and its 80 bits of precision can
hold 64-bit integers without precision loss; so I'd say the colorForth
way would be to write a set of macros akin to +, @, ! et al, which
basically compile down to single instructions. Then all you need are
words to get things into and out of the stack. (You might even want to
take advantage of the FILD and FIST instructions, which load integers
of various lengths directly to the FPU stack.)
Of course, if you wanted to dwell in the realm of bigints, you'd need
to look into multiple precision arithmetic, which... is always fun :)
But the number given < 2^40 (and you don't need signed arithmetic), so
you only need 40 bits anyway - well within the FPU's capability.
Just some thoughts... good luck!
Regards
Gwenhwyfaer
---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: colorforth-help@xxxxxxxxxxxxxxxxxx
Main web page - http://www.colorforth.com