> I am writing a program to generate Fibonacci numbers, but even using
UInt32's
> they get very large fairly quickly. The 500th Fibonacci number is 104
digits
> long, so I am going to use a custom list box (ref:ch.5, Advanced Palm
> Programming, Steve Mann) to display the first 20 or so digits, then pop up
a
> scrolling text box to see the entire really long number as wanted.
>
> quite willing to write my own Binary Coded Decimal routines for addition,
> subtraction, and assignment using arbitrarily long strings, but wondered
if
> anyone had BCD routines already written and willing to share?

If you are calculating a Fibonacci sequence, then all you need is addition.
Much easier to roll your own. Here you go:

void add(Char *z, const Char *x, const Char *y){
  const Char *p = x + StrLen(x);
  const Char *q = q + StrLen(y);
  Char *r = max(StrLen(x), StrLen(y)) ;
  Int16 C = 0;

  while(r >= z){
    Int16 P = (p > x ? (*p--) - '0': 0);
    Int16 Q = (q > y ? (*q--) - '0': 0) ;
    Int16 R = P + Q + C;

    C = R % 10;
    *r-- = '0' + R -10 * C;
  }

  if(C){
    MemMove(z + 1, z, StrLen(z) + 1);
    *z = '1'
  }
}

Buggers me why you want to do it on a Palm, though.



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to