comp.lang.ada
 help / color / mirror / Atom feed
* Big numbers
@ 2005-04-18 10:49 Doker
  2005-04-18 13:40 ` John B. Matthews
  0 siblings, 1 reply; 5+ messages in thread
From: Doker @ 2005-04-18 10:49 UTC (permalink / raw)


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

with Ada.Text_Io;

use Ada.Text_Io;

procedure Silnia is

A : Long_Long_Integer;

package Lng_Int_Io is new Ada.Text_Io.Integer_Io(Long_Long_Integer);

use Lng_Int_Io;

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;

begin

Put_Line("start");

loop

begin

New_Line;

Put("give a number:");

Get(A);

if A >28 then

Put_Line ("can't do with this");

raise Constraint_Error;

end if;

Put ("the result is ");

Put(Long_Long_Integer'Image(Silnia(A)));

exit;

exception

when Data_Error =>

Put("Data Error ");

Skip_Line;

when Constraint_Error =>

Put("Constraint Error ");

Skip_Line;

end;

end loop;

end Main;





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Big numbers
  2005-04-18 10:49 Big numbers Doker
@ 2005-04-18 13:40 ` John B. Matthews
  2005-04-18 18:53   ` Doker
  0 siblings, 1 reply; 5+ messages in thread
From: John B. Matthews @ 2005-04-18 13:40 UTC (permalink / raw)


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/



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Big numbers
  2005-04-18 13:40 ` John B. Matthews
@ 2005-04-18 18:53   ` Doker
  2005-04-18 21:22     ` Jacob Sparre Andersen
  0 siblings, 1 reply; 5+ messages in thread
From: Doker @ 2005-04-18 18:53 UTC (permalink / raw)


yes. Silnia is factorial - x!
I couldn't find in a dictionary :)

I don't know what implementation i have. I know i use GNAT and adaGIDE for Win.

But how can I count co big numbers? wIll I find any textbased aritmetic 
operation functions or a special type for that? 




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Big numbers
  2005-04-18 18:53   ` Doker
@ 2005-04-18 21:22     ` Jacob Sparre Andersen
  2005-04-19 18:19       ` Doker
  0 siblings, 1 reply; 5+ messages in thread
From: Jacob Sparre Andersen @ 2005-04-18 21:22 UTC (permalink / raw)


Doker wrote:

> yes. Silnia is factorial - x!
> I couldn't find in a dictionary :)
> 
> I don't know what implementation i have. I know i use GNAT and
> adaGIDE for Win.
> 
> But how can I count co big numbers? wIll I find any textbased
> aritmetic operation functions or a special type for that?

Take a look at:

   http://www.chez.com/bignumber/#Big_Number

Greetings,

Jacob
-- 
A: Yes.
>Q: Are you sure?
>>A: Because it reverses the logical flow of conversation.
>>>Q: Why is top posting frowned upon?



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Big numbers
  2005-04-18 21:22     ` Jacob Sparre Andersen
@ 2005-04-19 18:19       ` Doker
  0 siblings, 0 replies; 5+ messages in thread
From: Doker @ 2005-04-19 18:19 UTC (permalink / raw)


many thanks.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-04-19 18:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-18 10:49 Big numbers Doker
2005-04-18 13:40 ` John B. Matthews
2005-04-18 18:53   ` Doker
2005-04-18 21:22     ` Jacob Sparre Andersen
2005-04-19 18:19       ` Doker

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