comp.lang.ada
 help / color / mirror / Atom feed
From: "John B. Matthews" <nospam@nospam.com>
Subject: Re: Big numbers
Date: Mon, 18 Apr 2005 13:40:45 GMT
Date: 2005-04-18T13:40:45+00:00	[thread overview]
Message-ID: <nospam-5D84D3.09404418042005@news-rdr-01.ohiordc.rr.com> (raw)
In-Reply-To: d402ru$2meo$1@node2.news.atman.pl

In article <d402ru$2meo$1@node2.news.atman.pl>, "Doker" <doker0@wp.pl> wrote:

> program like that one can count only up to 29. what can i do to deal with 
> data up to 100?

> function Silnia (
>   Liczba : Long_Long_Integer)
>   return Long_Long_Integer is
> Efekt : Long_Long_Integer := 1;
> begin
>   for I in 2..Liczba loop
>     Efekt := Efekt * I;
>   end loop;
>   return Efekt;
> end;

Unless I misunderstand, Silnia returns the factorial of Liczba. Calculating 
Silnia(100) would require over 500 bits of storage. I must be missing 
something, because your program should fail for Liczba > 20. What is the size 
of your implementation's Long_Long_Integer?

Given the following bc program,

define f (x) {
  if (x <= 1) return (1);
  return (f(x-1) * x);
}
print "2^64: ", 2^64, "\n"
for (i = 20; i < 30 ; i ++ ) {
  print i, "!:  ", f(i), "\n"
}
print "100!: ", f(100), "\n"
print "log2(100!): ", l(f(100)) / l(2), "\n"
quit

I get the following output:

$ bc -ql fac.bc 
2^64: 18446744073709551616
20!:  2432902008176640000
21!:  51090942171709440000
22!:  1124000727777607680000
23!:  25852016738884976640000
24!:  620448401733239439360000
25!:  15511210043330985984000000
26!:  403291461126605635584000000
27!:  10888869450418352160768000000
28!:  304888344611713860501504000000
29!:  8841761993739701954543616000000
100!: 93326215443944152681699238856266700490715968264381621468\
      59296389521759999322991560894146397615651828625369792082\
      7223758251185210916864000000000000000000000000
log2(100!): 524.76499329005968632625

-- 
John
jmatthews at wright dot edu
www dot wright dot edu/~john.matthews/



  reply	other threads:[~2005-04-18 13:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-18 10:49 Big numbers Doker
2005-04-18 13:40 ` John B. Matthews [this message]
2005-04-18 18:53   ` Doker
2005-04-18 21:22     ` Jacob Sparre Andersen
2005-04-19 18:19       ` Doker
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox