Well I changed my verb to :-
fib=: 3 : 0 M. "0
if. 1>:y do. y else. (fib y-1)+fib y-2x end.
)
...and putting 2x insttead of 2 produced an extended integer result
without seeming to lose the timing improvements of M. !
fib 65
17167680177565
# ": fib 1000
209
ts 'fib 1000'
0.000511781 832
...which seems pretty fast for an 4 years old entry level Pentium processor!
> Date: Sun, 12 Sep 2010 05:44:24 -0700
> From: [email protected]
> To: [email protected]
> Subject: Re: [Jprogramming] Extended integers
>
> M. only works for the "direct" datatypes: boolean, character,
> integer, real, and complex.
>
>
>
> ----- Original Message -----
> From: Richard Donovan <[email protected]>
> Date: Sunday, September 12, 2010 2:29
> Subject: [Jprogramming] Extended integers
> To: J Programming <[email protected]>
>
> >
> > I am trying to learn M. (memoization) and as a by-product came
> > across the following:
> >
> > NB. define verb fib
> > fib=: 3 : 0 M. "0
> > if. 1>:y do. y else. (fib y-1)+fib y-2 end.
> > )
> >
> > fib 60
> > 1.54801e12
> > fib 60x
> > 1.54801e12
> > x: fib 60
> > 1548008755920
> >
> > ...and was wondering why
> >
> > fib 60x
> >
> > didn't result in an extended integer answer?
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm