U
Umesh
LOOKS FINE BUT IF FAILS TO WORK FOR n>12
WHAT ABOUT USING LINKED LISTS?
WHAT ABOUT USING LINKED LISTS?
[...]Umesh said:WHICH COMPILER(S) DO YOU USE?
GCC and other C compilers now support many of the new features of C99.
However, there has been less support from vendors such as Microsoft
and Borland that have mainly focused on C++, since C++ provides
similar functionality improvement.
GCC, despite its extensive C99 support, is still not a completely
compliant implementation; several key features are missing or don't
work correctly
[...]Umesh said:LOOKS FINE BUT IF FAILS TO WORK FOR n>12
WHAT ABOUT USING LINKED LISTS?
Army1987 said:"Keith Thompson" <[email protected]> ha scritto nel messaggio
Here's another program that uses a macro to compute factorials:
[code snipped]
The use of a macro is equally gratuitous, but at least this one
operates more usefully. On a system with 32-bit longs, either program
works only for arguments up to 12; using unsigned long rather than
long didn't add enough range to change that. With 64-bit longs, it
works for arguments up to 20. Neither version checks for overflow
(which would be fairly difficult to do)
#include <limits.h>
#include <errno.h>
long factorial(int n)
{
long f = 1;
int i;
if (n < 0) {
errno = EDOM;
return n % 2 ? LONG_MIN : LONG_MAX;
}
for (i = 1; i <= n; i++) {
if (f > LONG_MAX / i) {
errno = ERANGE;
return LONG_MAX
} else
f *= i;
}
errno = 0;
return f;
}
Fairly difficult?
Until you build it on a system whose int is 512 bit ;-)
#include <errno.h>Mark McIntyre said:(snip code)
Remember, you're callling this via a macro.
Walter Roberson said:Until you build it on a system whose int is 512 bit ;-)
and it happens to be relevant to the point, and the poster happensKeith Thompson said:[...]Umesh said:WHICH COMPILER(S) DO YOU USE?
GCC and other C compilers now support many of the new features of C99.
However, there has been less support from vendors such as Microsoft
and Borland that have mainly focused on C++, since C++ provides
similar functionality improvement.
GCC, despite its extensive C99 support, is still not a completely
compliant implementation; several key features are missing or don't
work correctly
The above two paragraphs are an uncredited direct quote from a
Wikipedia article,
<http://en.wikipedia.org/wiki/C_(programming_language)>.
There's nothing wrong with quoting from outside sources, and the
quoted material happens to be correct,
Keith Thompson said:If you really need to compute factorials, chances are you'll need them
for arguments that won't fit in any integer type, even if you have
512-bit integers.
He also seems to have learnt the horrible habit of top-posting.
Please do not top-post. Your answer belongs after (or intermixed
with) the quoted material to which you reply, after snipping all
irrelevant material. See the following links:
--
<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html>
<http://www.netmeister.org/news/learn2quote.html>
<http://cfaj.freeshell.org/google/> (taming google)
<http://members.fortunecity.com/nnqweb/> (newusers)
#include <errno.h>
#define factorial(n) \
} while (0) /*I'm not saying that it doesn't suck...*/
Mark McIntyre said:(snip macro that could suck bowling balls through a drinking straw)
*phew*
Umesh said:Which compiler do you use?
It's working fine in TC++ 3/4.5 & VC++ 6
Incorrect. "You" may be a single person, or it may be a group of
people being addressed collectively, or it may be a generic "somebody"
(though I believe that "one" is the english-pedant-correct word to use
for that last one).
osmium said:Do you understand that "you" refers to one particular person, and not a
group of people collectively?
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.