# representation of a number

4 messages
Open this post in threaded view
|

## representation of a number

 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
Open this post in threaded view
|

## Re: representation of a number

 > 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