メインコンテンツまでスキップ

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

ParameterType
valuenumber
minnumber
maxnumber

Returns

number


dbToGain()

function dbToGain(db): number;

Defined in: math.ts:108

Parameters

ParameterType
dbnumber

Returns

number


decimalPart()

function decimalPart(x): string | undefined;

Defined in: math.ts:86

Parameters

ParameterType
xstring | number

Returns

string | undefined


degree()

function degree(radian): number;

Defined in: math.ts:94

Parameters

ParameterType
radiannumber

Returns

number


gainToDb()

function gainToDb(gain): number;

Defined in: math.ts:112

Parameters

ParameterType
gainnumber

Returns

number


integerPart()

function integerPart(x): string | undefined;

Defined in: math.ts:79

Parameters

ParameterType
xstring | number

Returns

string | undefined


mapValue()

function mapValue(
value,
inMin,
inMax,
outMin,
outMax
): number;

Defined in: math.ts:98

Parameters

ParameterType
valuenumber
inMinnumber
inMaxnumber
outMinnumber
outMaxnumber

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

ParameterType
valuenumber
minnumber
maxnumber

Returns

number


radian()

function radian(degree): number;

Defined in: math.ts:90

Parameters

ParameterType
degreenumber

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

ParameterType
normalizedValuenumber
minnumber
maxnumber

Returns

number


stepValue()

function stepValue(value, step): number;

Defined in: math.ts:29

Parameters

ParameterType
valuenumber
stepnumber

Returns

number


toFixed()

function toFixed(x, fractionDigits?): number;

Defined in: math.ts:38

Parameters

ParameterType
xnumber
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

ParameterTypeDefault valueDescription
xnumberundefined-
significantDigitsnumberSIGNIFICANT_DIGITShow 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