math
Variables
SIGNIFICANT_DIGITS
const SIGNIFICANT_DIGITS: 15 = 15;
Defined in: math.ts:47
The significant decimal digits a double actually carries. A double holds a little under 16, so anything past this is the binary representation showing through rather than information.
Functions
clamp()
function clamp(
value,
min,
max
): number;
Defined in: math.ts:4
clamp value between min and max
Parameters
| Parameter | Type |
|---|---|
value | number |
min | number |
max | number |
Returns
number
dbToGain()
function dbToGain(db): number;
Defined in: math.ts:108
Parameters
| Parameter | Type |
|---|---|
db | number |
Returns
number
decimalPart()
function decimalPart(x): string | undefined;
Defined in: math.ts:86
Parameters
| Parameter | Type |
|---|---|
x | string | number |
Returns
string | undefined
degree()
function degree(radian): number;
Defined in: math.ts:94
Parameters
| Parameter | Type |
|---|---|
radian | number |
Returns
number
gainToDb()
function gainToDb(gain): number;
Defined in: math.ts:112
Parameters
| Parameter | Type |
|---|---|
gain | number |
Returns
number
integerPart()
function integerPart(x): string | undefined;
Defined in: math.ts:79
Parameters
| Parameter | Type |
|---|---|
x | string | number |
Returns
string | undefined
mapValue()
function mapValue(
value,
inMin,
inMax,
outMin,
outMax
): number;
Defined in: math.ts:98
Parameters
| Parameter | Type |
|---|---|
value | number |
inMin | number |
inMax | number |
outMin | number |
outMax | number |
Returns
number
normalizeValue()
function normalizeValue(
value,
min,
max
): number;
Defined in: math.ts:14
Normalize the value from 0 to 1, spreading the range evenly.
This is the linear mapping and takes no curve of its own; a Scale builds
whatever curve it needs on top of it.
Parameters
| Parameter | Type |
|---|---|
value | number |
min | number |
max | number |
Returns
number
radian()
function radian(degree): number;
Defined in: math.ts:90
Parameters
| Parameter | Type |
|---|---|
degree | number |
Returns
number
rawValue()
function rawValue(
normalizedValue,
min,
max
): number;
Defined in: math.ts:24
Convert normalized values back to raw values, spreading the range evenly.
The inverse of normalizeValue.
Parameters
| Parameter | Type |
|---|---|
normalizedValue | number |
min | number |
max | number |
Returns
number
stepValue()
function stepValue(value, step): number;
Defined in: math.ts:29
Parameters
| Parameter | Type |
|---|---|
value | number |
step | number |
Returns
number
toFixed()
function toFixed(x, fractionDigits?): number;
Defined in: math.ts:38
Parameters
| Parameter | Type |
|---|---|
x | number |
fractionDigits? | number |
Returns
number
toPrecision()
function toPrecision(x, significantDigits?): number;
Defined in: math.ts:69
Drop the binary artefact from a computed value.
Arithmetic on doubles leaves debris in the last couple of digits, and it accumulates: adding 0.1 to 5 twelve times gives 5.699999999999998 rather than 5.7, and the display of a control shows exactly that. Rounding to the digits a double can carry removes it, and adds nothing back — the value was already the result of a calculation whose own error is that size or larger.
This is not the same as rounding to a step. stepValue puts a value
on a grid the caller asked for and is a decision about the value; this only
removes what was never in the value to begin with.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
x | number | undefined | - |
significantDigits | number | SIGNIFICANT_DIGITS | how many digits to keep. The default is the only one that is purely artefact removal; a smaller number starts discarding real precision. |
Returns
number
Example
toPrecision(5.1 + 0.1) // 5.2, rather than 5.199999999999999