home .. forth .. colorforth mail list archive ..

Re: [colorforth] Euler Project Problems.


On Fri, May 9, 2008 at 9:21 PM, Gwenhwyfaer <gwenhwyfaer@xxxxxxxxx> wrote:
> 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
>
>

Great advice! Thank you.

I've learned about BIGNUMs in forth. Also assembler. I've seen the
Double extention wordset written by Neal Bridges for Retroforth ANS
compatabilitymodule.

I've learned about "Divide and conquer". I think I can get chuckBot to
play that one out in the display while you watch him manipulate the
registers. ( Can't wait that long? Remove the interval word from his
processes and everything he does on the screen is instantaineous. --
lol ) .

Marcel Hendrix's BIGNUM.frt is a great read. Thank You,  Josh Grahm
for the link.

http://home.iae.nl/users/mhx/bignum.frt

Lots to know in the world of multi-precision that I had not appreciated before.

I do want to try the FPU, and I think that it will be best for
multiplication and division but, I also want to do a simple bignum
algorithm for addition when the other two operations are not
necessary. This should make me at least a bit more conversant with the
idea.

I learned from the first two prob's that colorforth is cool for
collecting all of the macros and other words through-out the system
using the 'k' copy key. For instance, your proggy uses 'swap' so
copying 'swap' and any other dependancy, and moving it to a block,
along with it's documentation on it's own doc block and you can do
something most anyone else in the project can't do. You can show them
ALL of the code that is relevent. I like that.

Thanks again Gwenhwyfaer, for the advice and the luck, I'll need them both. :-)

Ray

-- 
Raymond St. Marie ii,
colorforthray.info

---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: colorforth-help@xxxxxxxxxxxxxxxxxx
Main web page - http://www.colorforth.com