Skip to content

Normalise

clamp clamps values to the -1…1 scale:

import { Bipolar } from 'https://unpkg.com/ixfx/dist/numbers.js';
Bipolar.clamp(-0.5); // -0.5
Bipolar.clamp(1.1); // 1

fromScalar will convert from 0..1 to -1..1, throwing an error if input is out of the 0..1 range.

import { Bipolar } from 'https://unpkg.com/ixfx/dist/numbers.js';
// Scalar 0 = -100%
Bipolar.fromScalar(0); // -1;
// Scalar 0.5 = 0%
Bipolar.fromScalar(0.5); // 0;
// Scalar 1 = 100%
Bipolar.fromScalar(1); // 1;

While fromScalar works with input values in 0..1 range, scale allows for an arbitrary input range

import { Bipolar } from 'https://unpkg.com/ixfx/dist/numbers.js';
// 50 is in the the middle of 0..10, thus 0%
Bipolar.scale(50, 0, 100); // 0

scaleUnclamped allows return values that exceed the range to also exceed the Bipolar range:

import { Bipolar } from 'https://unpkg.com/ixfx/dist/numbers.js';
// Scale the input value 10 with a scale of 0,4
Bipolar.scaleUnclamped(10, 0, 4); // 4
// Whereas:
Bipolar.scale(10, 0, 4); // 1