Chemistry · function

maxElementDrift

How far two element vectors have drifted apart, for the conservation harness.

Explained in Chemistry.

function maxElementDrift(a: Float64Array, b: Float64Array): number
import { maxElementDrift } from '@driftengine/chemistry';

Parameters

ParameterTypeDescription
aFloat64Array
bFloat64Array

In depth

Relative rather than absolute, because the elements in a burning world span many orders of magnitude at once: a scene may hold a kilomole of nitrogen and a micromole of sulphur, and an absolute tolerance either passes on a broken sulphur balance or fails on a correct nitrogen one.

With one exception that matters. Where both sides are effectively zero, a relative measure has nothing to divide by — and an element that appeared from nowhere would then report as no drift at all, which is the single failure this harness exists to catch. So the denominator has a floor of one, making the measure absolute in that regime.

Test-side rather than runtime: nothing in the simulation calls it.