I have written 14 calculators in my free time. Their source code is open source, so you can use the code for your own projects.
I started writing these calculators as Java applets in 1997. In 2015 I ported them to C language. The code is compiled to WebAssembly or asm.js using Emscripten so it can run inside Web browsers.
The complete source code size is about 70 000 lines of code.
The main purpose of compiling the code is to run coverage tests. The file coverage.out.old
holds the results of running all calculators with different inputs.
After making a change in the code, I run this test again and the output should not be changed. When adding a new feature to the calculators, I add the new case to the coverage, and change the results file if the results are correct.
These tests use the files Makefile
and coverage
.
You can use Makefile
to generate standalone executables. Just run make clean
and then make
.
If you want to build only one of the calculators, you can run make calculator
, where calculator
is one of the following words:
ecm
(integer factorization). This tests the calculator in English and Spanish.gaussian
(Gaussian integer factorization). This tests the calculator in English and Spanish.quad
(two-variable quadratic integer solver). This tests the calculator in English and Spanish.dilog
(discrete logarithm solver). This tests the calculator in English and Spanish.quadmod
(quadratic modular equation solver). This tests the calculator in English and Spanish.fsquares
(decompose number in sum of squares). This tests the calculator in English and Spanish.fcubes
(decompose number in sum of cubes). This tests the calculator in English and Spanish.tsqcubes
(decompose number in sum of two squares and a cube, fifth or seventh power). This tests the calculator in English and Spanish.contfrac
(continued fraction calculator). This tests the calculator in English and Spanish.polfact
(polynomial equation solver and factorization). This tests the calculator in English and Spanish.sumquad
(all sums of two squares). This tests all sums of squares in the calculator in English and Spanish.divisors
(all divisors of the number given by the user). This test the generation of divisors in the calculator in English and Spanish.
After building the calculators, you can run them. For example:
./polfact 0 "x^2+x+3" 2
The output is in HTML and it starts with a digit (this is used by the JavaScript code). All calculators can process expressions.
If you run the calculator without command line parameters, the program will show the expected arguments.
Software quality assurance is realized with the coverage test explained in the previous section and static analysis. The latter is done by tools that scan the source code. The programs do not run in this case.
Results of static analysis and code coverage of this software using Codacy.
Badges from SonarCloud:
If you like these calculators and you want to support free software, you can donate via Paypal by clicking in the button below: