converting the NRC to double-precision?
thebat137
09-25-2002, 02:40 PM
I've never used the Numerical Recipes before, but now a class I'm in is using NRC routines for our simulations. The professor encourages us to use double-precision for all our calculations, but it seems that many of the routines we need are only written for the "float" type. For the first assignment I had to carefully go through and make sure everything (including the special vector class variables and "#define TINY" float values and such) was converted to the appropriate double-precision form. Is there a quicker way to do this or, better yet, a readily available double-precision version of the library?
Sorry if this is a question that's answered trivially somewhere obvious. As I said, I'm new to this.
Thanks for any help anyone can offer.
- Anne
mathwiz
09-27-2002, 09:58 PM
Anne,
The C++ version of NR is all in double precision, and it is not very different from the C version, except for some C++ "wrappers", so you can probably just extract C code in double precision from it.
There is also an Appendix in the C++ version on how to convert things back to single precision! That appendix has a table that tells which routines have parameters that are different for float versus double, and what their values should be.
Another possible help might be pages 1362 and 1363 of the Fortran 90 (yes, Fortran ... yeccch!) NR version, which has a similar table of parameters. This is available on-line (see Books-On-Line on the main NR web page).
HTH
junderwood
10-15-2002, 09:19 PM
I too require NR in C to be all in double precision, and i came up with the following unix shell script to do the conversion, using sed. Use at your own risk, of course, but it's worked perfectly well for me. You do need to have all the files you want converting in the same directory though, or run in multiple times in each relevant directory.
for i in *.c *.h ; \
do sed -e'\
s/float/double/g;\
s/vector/dvector/g;\
s/matrix/dmatrix/g;\
' $i > ${i}.new ; \
mv $i ${i}.old ; mv ${i}.new $i ; \
echo $i ;
done
Unfortunately this forums autoformatting screws up the text, if you have difficulty, i can email you the correct shell script.
hope that helps,
jonathan.
junderwood
10-15-2002, 09:23 PM
oops, i forgot to mention that that script is for the bash shell.