Tone.js/Tone/core/util/Math.ts

41 lines
833 B
TypeScript
Raw Normal View History

/**
* 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;
}
2019-12-16 21:50:07 +00:00
/**
* 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);
}