Some mathematical C-programs for Linux
and console mode under Windows

Back to Stefan's home page


These C-programs are developed by Stefan Spännare and are free to copy.

Read the header of each C-program source code for instructions.
Compiling instructions and help for the programs.


Contents

1. References
2. Download SSCLN
3. Download SSPROG Updated!
4. π, Chudnovsky or Ramanujan Updated!
5. e=exp(1) and ln(2)
6. Euler C, γ
7. Γ(1/3) and Γ(1/4)
8. Catalan's constant G
9. Apery's constant ζ(3)
10. ζ(s)
11. A program to calculate some mathematical constants to large precision
12. Other e=exp(1) calculating programs
13. Fast hexadecimal e=exp(1) calculating programs
14. Digit statistics
15. Factorial
16. Prime numbers
17. Sorting
18. Programs for fun


1. References

1. The web page Mathematical constants and computation, by Xavier Gourdon and Pascal Sebah.

2. The web page Fast Algorithms and the FEE Method, by Ekatherina A. Karatsuba.

3. The web page The Karatsuba Method 'Divide and Conquer', by Ekatherina A. Karatsuba.

4. The article "Fast evaluation of transcendental functions", Problems of Information Transmission, vol. 27, (1991), p. 339-360,
by Ekatherina A. Karatsuba.

5. The article "Fast multiprecision evaluation of series of rational numbers", by Bruno Haible and Thomas Papanikolaou, 1997:

6. Some of the programs now use a very fast FFT by Takuya Ooura:

7. The web page CLN - Class Library for Numbers, by Bruno Haible et. al.

8. The documentation "Programs to Calculate some Mathematical Constants to Large Precision", by Stefan Spännare, September 2007:


2. Download SSCLN

The short C++ programs in this package use very fast functions in the CLN
(and GMP) packages to calculate some mathematical constants. The results
are interesting in themselves but can also be used to verify calculations
with other programs.

Download:

References:


3. Download SSPROG

All the programs in this package work fine in DOS (or CMD) mode under Windows XP,
2000 and probably also Windows 98. And also Windows 7 32-bit. And of course under
Linux if you compile the source code.

Important note. The Windows executables compiled with DJGPP under 32-bit
Windows XP DO NOT work on 64-bit Windows operating systems! The author
will investigate the best way how to solve this problem to the next release of
the package. Until then only version 2.26 (with 32-bit executables) is available
for Windows.

Important note November 5 2015. A bit late perhaps, but the author recommends that you use
the free Microsoft Visual Studio 2015 (that includes C and C++) to compile these C-programs
in Windows. It works very well and generates very fast code. On my ASUS notebook with
quad Intel i7 2670QM CPU sspi calculates π with about 2 million decimals in 19.04 seconds
on one CPU core. Under Tools in MS Visual Studio C++ you can open a console window
and compile the program with the following line. Some include files may be removed
(or perhaps added) in the C-program code to fit this compiler.

cl -O2 -o sspi.exe sspi.c fftsg_h.c -lm

Note. The Unix and Linux package now includes cbrun2l32, cbrun2l64, cbrun3l32
and cbrun3l64 executables for Linux (in the PRIMES directory) compiled using
Intel C/C++ 11.1 (icc) with the "-pc80" (long double) option. Versions are
available for both 32-bit and 64-bit Linux. The executables are compiled for
Intel Pentium 3, Pentium 4 and Core 2 Duo processors. Some of them work
well also on AMD CPUs.

To download all the programs below use one of the following files:


4. π, Chudnovsky or Ramanujan

This program calculates π to many decimal places using Chudnovsky or Ramanujan series. Very fast!
The program uses a very fast FFT (fftsg_h.c) by Takuya Ooura. Many thanks to him!

New! June 19 2012. Here is now available an updated version of sspi.c called sspi2.c. Most
of the new work was done already January 2010. Parts of the code (the procedures) now
have "how to use" comments and ladd, lsub, bigadd, bigsub and some other procedures
have temporary variables so that both input and output variables can be the same. The rest
of the code could benefit somewhat from that, but it is not changed. The programs on
this web-page are now mostly of historical interest, because much faster programs for
mathematical constants computations exist on the web that also use multi core support.


5. e=exp(1) and ln(2)

This program calculates e=exp(1) and ln(2) to many decimal places. Very fast!
The program uses a very fast FFT (fftsg_h.c) by Takuya Ooura. Many thanks to him!


6. Euler C, γ

This program calculates Euler C, γ to many decimal places. Very fast!
The program uses a very fast FFT (fftsg_h.c) by Takuya Ooura. Many thanks to him!


7. Γ(1/3) and Γ(1/4)

This program calculates Γ(1/3) and Γ(1/4) to many decimal places using AGM.
The program uses a very fast FFT (fftsg_h.c) by Takuya Ooura. Many thanks to him!


8. Catalan's constant G

This program calculates Catalan's constant G to many decimal places. Very fast!
The program uses a very fast FFT (fftsg_h.c) by Takuya Ooura. Many thanks to him!


9. Apery's constant ζ(3)

This program calculates Apery's constant ζ(3) to many decimal places. Very fast!
The program uses a very fast FFT (fftsg_h.c) by Takuya Ooura. Many thanks to him!


10. ζ(s)

This program calculates ζ(s) (for integer s ≥ 2) to many decimal places. Very fast!
The program uses a very fast FFT (fftsg_h.c) by Takuya Ooura. Many thanks to him!


11. A program to calculate some mathematical constants to large precision

This program uses some (not that fast) AGM based algorithms.
The program uses a very fast FFT (fftsg_h.c) by Takuya Ooura. Many thanks to him!


12. Other e=exp(1) calculating programs

Fast floating point method, might be numerically unstable:

Slower floating point method, probably numerically stable:

Long long int (64 bit) integer method, numerically stable:


13. Fast hexadecimal e=exp(1) calculating programs

Some of these programs use a very fast FFT (fftsg_h.c) by Takuya Ooura. Many thanks to him!

Chose the program that is fastest on your computer:

The following program is also needed for the final result:

Programs to convert from hexadecimal to decimal:


14. Digit statistics

Why not check if the digits seem to have a normal distribution:


15. Factorial

This program calculates large factorials (n!) exactly:


16. Prime numbers

All the prime number programs use a segmented implementation of Eratosthenes sieve.
They are very fast and require very little memory.

These two programs works theoretically for n ≤ 253-19.0·1015.

This program calculates (and print) all primes below n.

This program makes a table of the number of primes and twin primes below n.

These programs calculate Bruns constant and the Twin prime constant and the number
of primes and twin primes below n. Works theoretically for n ≤ 264-11.8·1019.
(using long double numbers). The programs cbrun2l* and cbrun3l* are significantly
faster than cbrunl for large n (≥ 1010).

Some results from the programs.


17. Sorting

Quick sort (very fast, non recursive and recursive):


18. Programs for fun


Author: Stefan Spännare
E-mail: stefan.sp@outlook.com
Latest update: 2015-11-05