representation of a number

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

representation of a number

Daniel Franzini
Hi all

I'm having some fun solving some programming problems in SPOJ
(www.spoj.pl, very very cool, check it out). The thing is that is need
to calculate some big fatorials (~100!). With FPC and the standard
integer types I was unable to perform the correct calculations because
100! is bigger than the largest number which can be represented with
those types. So I moved to the extended type and it worked quite well,
performing correct calculations and giving correct results. I started
wondering is this was a smart decision or if it is completely stupid
(i'm new to programming competitions and stuff like that).

The problem is that I'm unable to write the complete number on stdout.
Using extended I could only use scientific notation, which the judge
software does not seems to like. Question: what would be the correct
way to write the number on screen without using scientific notation
e.g.: 5! = 120 and not 5! = 1.2E+2?

--
Daniel

"Let us change our traditional attitude to the construction of
programs. Instead of imagining that our main task is to instruct a
computer what to do, let us concentrate rather on explaining to human
beings what we want a computer to do." (Donald Knuth)

"Yes, technogeeks can be funny, even if only to each other."
(http://www.boogieonline.com/revolution/science/humor/)"

"Man is driven to create; I know I really love to create things. And
while I'm not good at painting, drawing, or music, I can write
software." (Yukihiro Matsumoto, a.k.a. ``Matz'')
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: representation of a number

Marco van de Voort
> I'm having some fun solving some programming problems in SPOJ
> (www.spoj.pl, very very cool, check it out). The thing is that is need
> to calculate some big fatorials (~100!). With FPC and the standard
> integer types I was unable to perform the correct calculations because
> 100! is bigger than the largest number which can be represented with
> those types. So I moved to the extended type and it worked quite well,
> performing correct calculations and giving correct results. I started
> wondering is this was a smart decision or if it is completely stupid
> (i'm new to programming competitions and stuff like that).

Keep in mind that the extended type has limited precision. It can contain
large values, but does so by only "remembering" the upper +/- 18 digits,
sign and exponent.

If it is a content, I think  they want you to calculate a number larger than
the size of normal types is to force you to deal with it, and define your
own arithmetic for very large numbers.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: representation of a number

Daniel Franzini
On 4/1/07, Marco van de Voort <[hidden email]> wrote:
>
> Keep in mind that the extended type has limited precision. It can contain
> large values, but does so by only "remembering" the upper +/- 18 digits,
> sign and exponent.
>

OK, i will work on that

> If it is a content, I think  they want you to calculate a number larger than
> the size of normal types is to force you to deal with it, and define your
> own arithmetic for very large numbers.
>

it's not a content....its just a list of programming problems to be
solved with a ranking system....sometimes they organize some sort of
contest but the main thing is just a list of classical and challenge
problems waiting to be solved....they count the amount of memory and
execution time of the algorithm and sort the solutions with these
criteria awarding more points to the best solutions...just for
fun...nothing serious...


> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
 thanks anyway

--
Daniel

"Let us change our traditional attitude to the construction of
programs. Instead of imagining that our main task is to instruct a
computer what to do, let us concentrate rather on explaining to human
beings what we want a computer to do." (Donald Knuth)

"Yes, technogeeks can be funny, even if only to each other."
(http://www.boogieonline.com/revolution/science/humor/)"

"Man is driven to create; I know I really love to create things. And
while I'm not good at painting, drawing, or music, I can write
software." (Yukihiro Matsumoto, a.k.a. ``Matz'')
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: representation of a number

Marco van de Voort
> On 4/1/07, Marco van de Voort <[hidden email]> wrote:
> >
> > Keep in mind that the extended type has limited precision. It can contain
> > large values, but does so by only "remembering" the upper +/- 18 digits,
> > sign and exponent.
> >
>
> OK, i will work on that

You could search for the phrase "MPI" if you want to know more about very
long integers.
 
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal