Skip to content
/ dmath Public

Deterministic Math Library for Game Projects Based on Musl

License

Notifications You must be signed in to change notification settings

pocketpy/dmath

Repository files navigation

dmath

Python GitHub GitHub 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>

int main(){

// You can check this macro to ensure that `dmath` is used.
#ifndef _DMATH_H
    abort();
#endif

    double x = log(10);
    printf("log(10) = %f\n", x);
    return 0;
}

Tested Platforms

We have tested dmath on the following platforms and configurations.

Job OS Arch Compiler
build_ubuntu Ubuntu 22.04 x86_64 gcc
clang
build_ubuntu_multiarch Ubuntu 22.04 x86 gcc
clang
aarch64 gcc
clang
armv7 gcc
clang
build_macos MacOS 14 x86_64 clang
build_win32 Windows 2022 x86_64 cl

References

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

License

MIT License

About

Deterministic Math Library for Game Projects Based on Musl

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published