zsbc, a portable integer calculator using gmp ============================================= Date: 2015-11-01 18:55 +0100 Contents: I. WHAT IS ZSBC? II. WHY ZSBC? III. LICENCE IV. COMPILATION AND INSTALLATION I. WHAT IS ZSBC? It is a calculator supporting simple arithmetic along with big integers, as provided by the GNU MP library. It is similar to bc and one goal of this program is to be compatible with bc scripts. zsbc stands for "Zero Scale BC": the focus is not on real number management but on integers. Because the author of these lines wanted bc tests to be applicable to zsbc, zsbc got compiled with the bc number library, in addition to gmp. By default zsbc starts with gmp integers (mpz_t) but if provided with the command-line argument --numlib bc or if during execution you enter the statement libswitch "bc" then the bc number library will be used (instead of gmp' mpz_t) and decimal numbers will be managed as per bc standard => among other things, taking into account the value of the "scale" variable, that defines the number of decimals to keep after the comma. As with bc program, the bc number library provides the sqrt function (square root). Also when invoked with --numlib bc, zsbc can be provided the -l option, that'll the load bc mathlib library, defining the functions a (arc tangent), c (cosine), s (sine), e (exponent), l (natural logarithm) and j (Bessel function). Please read the file "FAQ" provided with zsbc to have more details about the links between bc and zsbc. II. WHY ZSBC? To have fun. To learn bison/flex programming. To do some tests and checks around cryptography. To deal with big integers, you have bc, PARI/GP, python, ... And now you have zsbc! III. LICENCE See COPYING file that comes along with the package the program belongs to. IV. COMPILATION AND INSTALLATION 1) Preliminary note about GMP versus MPIR zsbc needs a "bignum" library, that is, a library capable of working on big numbers. GMP was chosen as the default, "canonical" one to zsbc. GMP is the GNU Multi Precision Arithmetic Library. Initially GMP was intended as being the default library in both Linux and Windows. However, the author of these lines could not build zsbc.exe along with libgmp using MSVC. It would work only with mingw. As msvc compilation is deemed an important feature, decision was made to use the "natural" substitute to GMP for msvc compilation, that works natively under Windows: MPIR. In the end the following was tested and documented. Linux compiled with libgmp Windows/mingw compiled with libgmp Windows/msvc compiled with libmpir That said, given the fact that MPIR is so close to GMP (as of writing of this text, September 2015), it is believed that MPIR can successfully compile with zsbc in all cases, including Linux and Windows/mingw. 2) Linux build 2.1) Making the GMP development library available As written above, while MPIR is certainly suitable for Linux compilation, GMP was tested and documented. "GMP library" (sometimes I simply write "libgmp") is the GNU Multi Precision Arithmetic Library. You can download the source and compile it but if using a package-enabled system, it is recommended to install the package source. The deb package name is libgmp-dev. The rpm package name is libgmp-devel. The GNU Multiple Precision Arithmetic Library homepage is https://gmplib.org 2.2) Making the readline development library available The readline library is necessary to compile zsbc under Linux (unless the --disable-readline option is used in the configure script). The deb package name is libreadline-dev. The rpm package name is readline-devel. The GNU Readline Library homepage is https://cnswww.cns.cwru.edu/php/chet/readline/rltop.html Note The readline library is not used in Windows. 2.3) Compilation The file of name INSTALL, distributed with zsbc source files, gives instructions to compile and install the program, using the usual ./configure make make install sequence. This INSTALL file is the one provided by default by autotools. 3) Windows build with mingw Done successfully with both 32-bit (mingw) and 64-bit (mingw-w64) compilers. There does not seem to be Windows-ready libgmp binaries around that mingw could use. This part - buid libgmp Windows binaries and link zsbc with - is the main factor of complexity. Only static linking with libgmp, using mingw compiler, was done. 3.1) Install mingw At first you have to download and install Mingw *along with msys*. Mingw homepage: http://www.mingw.org 3.2) Get and compile libgmp You have to download the source of the GNU Multi Precision Arithmetic Library and build it with mingw. Build needs be done from an msys terminal, using mingw gcc compiler. The GMP library homepage: https://gmplib.org 3.3) Update makefile.mingw You have to tune makefile.mingw depending on how you built the GMP library, to designate the correct locations of GMP's include and lib files. After libgmp build, look for the files gmp.h libgmp.a 3.4) Build zsbc.exe Reminder Under windows, zsbc does not use the readline library. For a "release" build, enter top source directory and run mingw32-make.exe -f makefile.mingw For a "debug" build, enter top source directory and run mingw32-make.exe -f makefile.mingw DEBUG=1 4) Windows build with msvc 4.1) Install msvc Discussing downloading and installation of MSVC is beyond the scope of this document. Please note the version successfully used to build libmpir (replaces libgmp for msvc build, see notes above) and zsbc is Microsoft Studio Community 2015, available for free. URL: https://www.visualstudio.com 4.2) Get and compile libmpir As of September 2015, downloading and extracting archive content will produce a ready-to-compile source tree under the directory mpir-2.7.0 Open the file (whatever)\mpir-2.7.0\build.vc14\mpir.sln with MSVC and generate the project, after selection of the proper generation type, win32 versus x64 and release versus debug. The MPIR homepage: http://mpir.org 4.3) Update makefile.vc You have to tune makefile.vc depending on how you built the MPIR library, to designate the correct locations of MPIR's include and lib files. After libmpir build, look for the files gmp.h mpir.lib gmp.h above is not a typo. gmp.h and mpir.h are 100% identical and illustrate to which extent MPIR can substitute to GMP: only the compilation needs be updated (to link against mpir), not one line of code had to be updated to switch from GMP to MPIR. 3.4) Build zsbc.exe For a "release" build, enter top source directory under MSVC command-line environment and run nmake -f makefile.vc For a "debug" build, enter top source directory under MSVC command-line environment and run nmake -f makefile.vc DEBUG=1