S
Saurabh Saxena
can we calculate the 73! value in c or c++ without loss of significant digits.
Saurabh Saxena said:can we calculate the 73! value in c or c++ without loss of significant digits.
Saurabh said:can we calculate the 73! value in c or c++ without loss of significant digits.
digits.Saurabh said:can we calculate the 73! value in c or c++ without loss of significant
Saurabh said:can we calculate the 73! value in c or c++ without loss of
significant digits.
osmium said:digits.
Oddly enough, the range of a pocket scientific calculator is greater than
that of C for long or even double precision numbers. And you will note that
the calculator will not compute 73!.
It could be done but it would require
coding (or acquiring) a method of dealing with very large numbers.
Peter said:Not really, you just need to separate the mantissa from the exponent. I
don't remember how big the exponent was for 1000!, I only *think* it had to
be expressed in scientific notation on my calculator (too lazy to try it
again).
The method is simple: take advantage of the fact that a * b == pow(10,
log10(a) + log10(b)). I'll leave the rest on the OP - after all, I'm not
going to do his homework for him! ;-)
osmium said:The problem says "without loss of precision".
I think the homework was only a yes or no answer to a poorly phrased
question, not an actual solution.
Saurabh said:can we calculate the 73! value in c or c++ without loss of significant digits.
Martin said:73! is about the 351st power of 2. There is no type in C or C++ that is
guaranteed 351 bits of precision.
jacob said:Using lcc-win32 we have:
#include <stdio.h>
#include <qfloat.h>
jacob said:Using lcc-win32 we have:
#include <stdio.h>
#include <qfloat.h>
int main(int argc,char *argv[])
{ .... snip ...
}
Output
D:\lcc\mc50\test>f 75
75! = 2.480914081139539809194647711659403366
092624388657012283779589451265584267757e+109
75! / 74! = 75
CBFalconer said:jacob said:Using lcc-win32 we have:
#include <stdio.h>
#include <qfloat.h>
int main(int argc,char *argv[])
{
... snip ...
}
Output
D:\lcc\mc50\test>f 75
75! = 2.480914081139539809194647711659403366
092624388657012283779589451265584267757e+109
75! / 74! = 75
73! has precisely 16 trailing zeroes, in decimal notation. So the
above cannot be correct. (The original required no loss of
significant digits)
I believe C99 has some long double types that could be mapped into
your qfloat system, which would give you something very close to
standardization.
I believe that the original question was: "Can 73! be computed
using C without loss of significant digits?"
If you only use the standard types for any current implementation,
the answer is patently NO.
Saurabh said:can we calculate the 73! value in c or c++ without loss of significant digits.
Mark said:Saurabh,
As you perhaps already know, the value of 73! is
44701154615126843408912571381250511100768007002829050158190800923704\
22104067183317016903680000000000000000
This is a value whose precision (number of digits in its representation)
exceeds that of all integral and floating types defined by (drum roll
please) ... THE STANDARD.
In other words, to compute 73! using Standard
C, you'll need to develop a multiple-precision data structure and
associated computation procedure. There are myriad ways to do this;
Knuth Vol. 2 is a useful reference.
However, since the term "multiple-precision" is probably nowhere
mentioned in (drum roll please) THE STANDARD, you may want to be careful
about mentioning it any further, lest one of the newsgroup nannies, in
their never-ending quest for absolute purity, raps you on the knuckles
with a hard ruler.
Richard said:Not so. The Standard imposes no maxima on precision levels - only minima.
Nick said:.... snip ...
I believe that the original question was: "Can 73! be computed
using C without loss of significant digits?"
If you only use the standard types for any current implementation,
the answer is patently NO.
If on the other hand, you are creative and devise some kind
of algorithm where you have multiple "words" (32 bit or 64 bit)
representing the number, then the answer is YES.
Mark said:Though your statement about imposing no maxima is technically correct,
it's not precisely relevant to the problem at hand.
The task is to find
a method for computing 73! that works on all implementations abiding by
the standard: in which case the minima are relevant, not the maxima.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.