Tone.js/Tone/core/util/Math.ts
Yotam Mann aaf880c925
Using web-test-runner for tests, updating import paths (#1242)
* WIP moving tests to web-test-runner

* updating thresholds

* Adding file extensions

* Testing integrations

* linting

* fixing dep

* moving back to root dir

* prettier all of the files

* updating eslint rules to use with prettier

* remove import package

* moving tsignore around

* removing unneeded ignores

* all tests run on puppeteer, no need for testing guards

* linting

* import type syntax

* cleaning up

* Update package.json
2024-05-03 14:31:14 -04:00

40 lines
832 B
TypeScript

/**
* The threshold for correctness for operators. Less than one sample even
* at very high sampling rates (e.g. `1e-6 < 1 / 192000`).
*/
const EPSILON = 1e-6;
/**
* Test if A is greater than B
*/
export function GT(a: number, b: number): boolean {
return a > b + EPSILON;
}
/**
* Test if A is greater than or equal to B
*/
export function GTE(a: number, b: number): boolean {
return GT(a, b) || EQ(a, b);
}
/**
* Test if A is less than B
*/
export function LT(a: number, b: number): boolean {
return a + EPSILON < b;
}
/**
* Test if A is less than B
*/
export function EQ(a: number, b: number): boolean {
return Math.abs(a - b) < EPSILON;
}
/**
* Clamp the value within the given range
*/
export function clamp(value: number, min: number, max: number): number {
return Math.max(Math.min(value, max), min);
}