This project is still in its infancy and is updated regularly.
This project is a collection of code written in C89/C90 (commonly called ANSI C) for mathematicians and physicists to use on various types of projects. It started with rss_ringoccs, a suite of tools written for processing the Cassini radio science data, which is written mostly in C (but also Python), but eventually grew beyond the scope of just astronomy.
There are no dependencies other than a C compiler and the C standard library. The library is written entirely in ISO C89/C90 compliant code, and no C99/C11 or GCC extensions are used. It compiles with C99 and C11/C18 compilers, so it is more fitting to say it is written in the intersection of these standards.
A CMakeLists.txt file is provided which allows libtmpl to be built
portably across various architectures
(x86-64, aarch64, sparc64, ppc64, mips, and more) and
operating systems (GNU / Linux, FreeBSD, macOS, Windows, etc.). To compile, use
cmake -S . -B build
cmake --build build --config Release
The build process can be parallelized as well:
cmake -S . -B build
cmake --build build --config Release -j
There are several options that control how libtmpl is compiled. To see descriptions of these, run
cmake -S . -B build -LH
You may then install libtmpl using (requires sudo / administrator privileges)
cmake --install build
A Makefile is provided that works well on any platform that provides
GNU Make. Run the Makefile with (FreeBSD users should use gmake)
make
The Makefile is parallelizable which saves quite a bit of time, especially on emulated architectures:
make -j
The Makefile has many flags that determine how libtmpl is compiled. Use
make help
to see a description of each command-line option.
Afterwords, if you would like to install libtmpl in /usr/local/lib, run
sudo make install
To remove all build and .so files, run:
make clean
To uninstall, run:
sudo make uninstall
To install into a directory tree other than /usr/local, set the prefix
variable when running make, e.g. make prefix=/opt install
will install into/opt/lib etc.
A bash script is available, but results in a larger and less performant build.
By default it has nearly all compiler warnings enabled for gcc and clang
(including -Weverything with clang) and is used internally as a
quick error check.
To use, run:
sudo bash make.sh
There are various options that can be passed to this script. Use
bash make.sh --help
to see a description for each of them. Remove libtmpl by running
sudo bash make.sh --remove
A very primitive batch script exists for Windows users. This allows you to build libtmpl on Windows with minimal dependencies, you need only a C compiler. Run the script with
make.bat
This uses MSVC by default. To select a different compiler, clang-cl
for example, use
make.bat clang-cl
cl, clang-cl, clang, and gcc are supported by the batch script.
This creates libtmpl.lib or libtmpl.a in the top directory of libtmpl.
The make.bat file skips assembly code, using only C source files.
Because of this it is recommended that you install CMake and follow the
build instructions provided above. This results in a far more performant build.
Almost all mathematical functions of real or complex variables are computed via one of two methods:
- Argument reduction:
Reduce the input
xto a small range[a, b]and then accurately compute the function in the range using some numerical method. Ex:sin,cos,log,sqrt.
- Separate argument into windows:
Determine if the input
xfalls in one of the ranges[a_0, b_0], ...,[a_n, b_n], allowing fora_0 = -infandb_n = +inf, and then compute the function in this range using some numerical method. Ex:Bessel_J0,Bessel_I0. Usually Taylor series for small inputs and asymptotic expansions for large.
The numerical methods are typically one of the following:
- Taylor / Maclaurin Series.
- Pade Approximants.
- Asymptotic Expansions.
- Chebyshev Polynomials.
- Remez exchange.
Inside data/ lies all of the code for computing the coefficients of these
approximations. None of the code is directly used in libtmpl, indeed most
files are in Python. This directory is kept in this repository for the sake
of studying algorithms. In particular, for seeing where these approximations
come from.
All functions have examples of basic usage.
All header and inline files for libtmpl.
The source files. Mostly .c, but a few assembly files are found for certain
architectures.
Time and accuracy tests of libtmpl against other libraries. To run these
tests will require these libraries being available. Running these tests is
not required, and they are mostly for internal use and to verify the
algorithms implemented in libtmpl.
Language bindings, or wrappers, are provided for C++, Python,
and IDL (also the Free/Open-Source implementation GDL). All bindings require
libtmpl being built beforehand. The source codes used to live in this
repository, but have since moved to their own for easier management. These
can be found via the following links.
libtmpl is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libtmpl is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with libtmpl. If not, see <https://www.gnu.org/licenses/>.