Skip to content
This repository was archived by the owner on Feb 21, 2026. It is now read-only.
/dmathPublic archive

Repository files navigation

dmath

PythonGitHubGitHub release

dmath is a deterministic math library for game projects that running on standard mobile (Android/iOS) and desktop platforms (Windows/Linux/MacOS).

dmath is a drop-in replacement for the math library in C11, based on musl-libc v1.2.5 with modifications to ensure that all floating-point operations are deterministic across different platforms and compilers. Although musl-libc is primarily designed for Linux, dmath can be used on Windows and MacOS. pocketpy uses dmath as its math library when compiled with -DPK_ENABLE_DETERMINISM=ON.

Installation

First clone this repo recursively:

git clone --recursive https://github.com/pocketpy/dmath

Then add the following line to your CMakeLists.txt:

add_subdirectory(<path_to_dmath_repo>)
target_link_libraries(<your_target>dmath)
if(MSVC)
# Force multiple definitions to be allowed in MSVC.target_link_options(<your_target>PRIVATE/FORCE:MULTIPLE)
endif()

Usage

// CMakeLists.txt will redirect <math.h> to "dmath/include/public/math.h".// You don't need to modify your existing code.#include<math.h>#include<stdio.h>intmain(){
// You can check this macro to ensure that `dmath` is used.#ifndef_DMATH_Habort();
#endifdoublex=log(10);
printf("log(10) = %f\n", x);
return0;
}

Tested Platforms

We have tested dmath on the following platforms and configurations.

JobOSArchCompiler
build_ubuntuUbuntu 22.04x86_64gcc
clang
build_ubuntu_multiarchUbuntu 22.04x86gcc
clang
aarch64gcc
clang
armv7gcc
clang
build_macosMacOS 14x86_64clang
build_win32Windows 2022x86_64cl

References

https://box2d.org/posts/2024/08/determinism/

License

MIT License

About

Deterministic Math Library for Game Projects Based on Musl

Resources

Code of conduct

Stars

3 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages