I started to read the book “numerical recipes in C”… I try make my programs more efficients and faster… So, is the same thing, to use C or C++? I know that C++ is a super-set of C… But, are there differences between “cmath” library (c++) with “math.h” library(c)? It will intervene in the velocity of execution?… in order to that… i can use C++ without any difference with a C program?
Share
First off, C++ is not a superset of C. Though there are many similarities, there are also differences, and neither is a subset of the other.
Now that we have that out of the way, Numerical Recipes uses an especially simple subset of C, and you should not encounter many difficulties in using the code in a C++ program. Most of the algorithms will Just Work without modification[1].
You shouldn’t worry about details like
<cmath>; on most platforms, it’s just a thin shim over the C math headers, and does not introduce any overhead. Broadly, this is true of C++ in general: when you’re writing code that looks like C code, little or no additional overhead is introduced.[1] In as much as they work in C; Numerical Recipes is a useful reference, but the programs contained therein are not entirely bug-free, nor are all of the algorithms state of the art. Some of the algorithms are numerically poor choices. If you become seriously interested in any of the topics discussed, be sure to read the references, and then to look for more current material on the subject.