@(none) said:
Hi, I need to learn the necessary and sufficient C programming
knowledge in order to be able to implement number theory and
graph theory algorithms (as RSA or Dijkstra algorithms). No
system programming no network programming nor graphic
programming.
C is not a precise language, which makes it very hard to do hardcore
mathematics in it. Its possible, but you basically have to compromise
either on portability or speed, unless you are willing to really become
expert on the language.
Just learning how C deals with integers should give you reason to
reconsider using it as a language for this kind of thing. To get some
sort of sanity out of the language you have put letters like "U" or "L"
at the end of all your inline declared numbers. I would recommend
testing on no less than 7 compilers all with maximum warning settings
and using lint if you plan on having any degree of portability.
But, no compiler or lint-like utility that I am aware of can actually
assist programmers with any kind of numerical determinism. You are
basically forced to become an expert at the language which may take
many weeks or months (Python can be learned in a few hours and doesn't
have these problems).
Here are some examples:
int a, b;
unsigned int c, d;
...
if (a < 0) a = -a;
return sqrt (a); /* Undefined result. */
b = a >> 24; /* A completely meaningless operation */
if ((a % c) == (b % c))
/* a and b having the same residue mod c is insufficient
to make this condition true */
d = (a - b) % c;
/* d is zero when a and b are equal mod c, but otherwise
will not necessarily be equal to the correct residue
mod c */
And just to annoy mathematicians, C uses "*" for two different
operations as well as part of the comment brackets (and uses "/" for
comment brackets as well).
C is just a rotten language for doing real mathematics. Most of these
problems go away in other languages -- especially those that support
arbitrary precision integers (like Java, Python, etc.)
Any advice ? Any link to a non verbose reference ?
Yeah, pick a different language.