caelum0x 11e53383c7 feat: deterministic natural logarithm
The rocket equation produces par-fuel and delta-v figures that ship inside
level data. A value that differs between platforms is the same class of bug
as a desynced replay, so log belongs in the kernel rather than falling back
to the host libm.

Reduce x = m*2^k with m in [2/3, 4/3), then ln(m) = 2*atanh((m-1)/(m+1)).
Accurate to <1e-13 against the host libm across the tested range.
2026-09-15 01:05:10 +03:00
2026-04-07 15:59:37 +03:30
2026-02-08 20:00:27 +03:30
2026-02-08 20:15:49 +03:30
2025-06-06 07:21:41 +03:30
2026-09-15 01:05:10 +03:00
2025-06-01 21:32:45 +03:30
2026-02-08 20:15:49 +03:30
2025-05-26 19:41:12 +03:30
2026-04-07 15:59:37 +03:30
2024-11-23 16:08:24 +03:30
2024-12-15 14:41:31 +03:30
2023-08-20 09:23:47 -07:00
2023-08-06 22:13:14 -07:00
2024-11-23 12:46:32 +03:30
2024-12-19 23:09:21 +03:30
2024-12-20 15:08:27 +03:30

planck-deterministic

A fork of planck.js (MIT, Erin Catto / Ali Shakiba) with a cross-platform deterministic math kernel.

Why

Upstream planck calls the host Math.sin, Math.cos, Math.atan2 and Math.random. IEEE-754 guarantees + - * / and sqrt are correctly rounded, so those are identical everywhere — but ECMAScript explicitly permits an implementation-dependent approximation for the transcendental functions, and every engine forwards them to the host libm. Those results differ between ARM64/JavaScriptCore (iOS) and x86-64/V8 (desktop).

Rot.setAngle and Sweep.getTransform call sin/cos for every rotating body on every step. So a simulation shared between a mobile build and a desktop build diverges as soon as anything rotates. That breaks replay portability, server-side replay verification, and any leaderboard built on re-simulating a replay.

What changed

  • Added src/common/DeterministicMath.ts — sin, cos, exp, atan, atan2, sqrt and a seeded PRNG, built from + - * / and comparisons only. Coefficients and the Cody-Waite range reduction follow fdlibm (Sun, freely distributable), the reference implementation most libms derive from. Accuracy is within a few ulp of the host libm.
  • Rewired the nine hoisted aliases in Math.ts, Matrix.ts, Rot.ts, Sweep.ts and dynamics/Position.ts to use it. No host libm call remains anywhere in src/.
  • Exported the kernel (DeterministicMath, seedRandom) so consumers can share the exact same functions the solver uses and seed the PRNG for reproducible replays.

Every upstream test still passes, plus new determinism tests including a check that a simulated free fall matches the closed-form analytic solution.

import { World, seedRandom, DeterministicMath } from "planck-deterministic";

seedRandom(12345); // before a run, and before replaying it

Upstream

This tracks planck.js v1.5.0. Upstream docs and API below.


Planck.js

Planck.js is JavaScript/TypeScript rewrite of Box2D physics engine for cross-platform HTML5 game development.

Motivations

  • Taking advantage of Box2D's efforts and achievements
  • Developing readable and editable code in JavaScript/TypeScript
  • Providing idiomatic JavaScript/TypeScript API
  • Optimizing the library for web and mobile platforms

Documentation

Examples

Discord

Made with Planck.js

Report Issues

To speed up resolving issues, please provide testbed code to reproduce the issue.

Description
2D JavaScript Physics Engine
Readme 32 MiB
Languages
TypeScript 99.1%
HTML 0.5%
CSS 0.2%
JavaScript 0.2%