This is a experimental math lib based on musl libc, aiming at the determinism on all platforms. Different from musl libc, there are no code for a specific platform(like asm instructions).
Tag Dev
: developping
Tag Finished
: the branch finished its job, and is going to be deprecated
Main branch. Other developping branches are created based on this, and will finally merged into main
.
Finished
A test on mac showing that mac didn't turn off fma. Fixed.
Dev
Test trigonometry operations using musl.
Finished
Test basic operations like sum, without musl. Validates the stability of basic operations across platforms.
Finished
Test + - * /
, double to float across platforms.
Finished
A version from determinism_asm_sin
, uses the origin musl libc.
- Math functions: no implementations are changed.
math.h, features.h, float.h
are included as#include ""
. - -1ULL: -1ULL and -1ULL>>1 are replaced by macros.
- features.h: add
hidden
definition, which is required byxxx_data.h
andlibm.h
.
Simple tests with determinism_test.c
. Tested on Windows11, 22H2, x64_64, AMD Ryzen Threadripper 3990X.
Cumulative error is found in the test. A small number equal to DBL_EPSILON is produced during the computation. For example, sqrt(2), the result of pow(sqrt(2), 2) is 2.0+2*DBL_EPSILON. The same phenomenon is found on the following compilers.
No problem.
No problem.
No problem.
Function | Example | Checked |
---|---|---|
acos | ✅ | |
asin | ✅ | |
atan | ✅ | |
atan2 | ✅ | |
cbrt | ✅ | |
ceil | ✅ | |
cos | ✅ | |
exp | ✅ | |
fabs | ✅ | |
floor | ✅ | |
fmax | ✅ | |
fmin | ✅ | |
fmod | ✅ | |
log | ✅ | |
log10 | ✅ | |
log2 | ✅ | |
modf | ✅ | |
pow | ✅ | |
scalbn | ✅ | |
sin | ✅ | |
sqrt | ✅ | |
tan | ✅ | |
trunc | ✅ |
Except for windows, CI in Github Actions tests this repo on:
Ubuntu 22.04, x64, gcc and clang
Ubuntu 22.04, x86 aarch64 armv7, gcc and clang
Macos 14, clang
Origin musl libc: the original musl libc.
Keepping math only: deleted most of the code.
Deleted ./arch: code for different platforms, file like fp_arch.h
and float.h
defines behavior for specific platforms.
Deleted ./compat, ./crt, ./dist, ./ldso, ./tools: not related with math.
Modified ./include: only kept float.h, math.h, stdint.h
, which are related to math.
Modified ./src: only kept folders related by math.h
. ./src/include/features.h
is included by math.h
, kept. ./src/internal/libm.h
is included by many math functions, kept. ./src/math
, kept.
!! Deleted ./src/math/(some platform) folders: some functions (especially sqrt) have the corresponding assembly instruction on different platforms. These folders are deleted to make sure that all the functions are implemented by ourselves.
Gather files: put files together.
After deletion, I put the rest files like this:
./include
| -- features.h
| -- float.h
| -- libm.h
| -- math.h
| -- stdint.h
./src
| -- math
| -- math function files
Integrate math.h: integrate include files into math.h
Deleted features.h
: platform feature defines.
Deleted float.h, libm.h, stdint.h
.
Modified math.h
: paste code from float.h, libm.h, stdint.h
.
Modified ./src/math: changes, deletions of math functions
Deletion: These functions for calculation are kept. input and output are double
.
acos, asin, atan, atan2, ceil, cos, exp, fabs, floor, fmod,
log, log10, log2, modf, pow, scalbn, sin, sqrt, tan, trunc
Internal functions like __cos.c
, error handling functions like __math_invalid.c
are kept.
Addition: functions for degree computation, reduction, factorial, gcd.
double degrees(double);
int factorial(int);
double fsum(double*, int);
int gcd(int, int);
double radians(double);
Modification: all files' include headers are changed.
Files like cos.c
including libm.h
are changed to math.h
.
Files like __fpclassify.c
including math.h, stdint.h
are changed to math.h
.