Skip to content

Latest commit

 

History

History
73 lines (48 loc) · 2.1 KB

Limit.md

File metadata and controls

73 lines (48 loc) · 2.1 KB

Limit

var my_bound = new Limit(low, high) // when installed onto the window
var my_bound = new Elements.Limit(low, high)

This is one way to make a new "bound", simply put the lower and upper bounds into the constructor and use the functions on it, as you can see below. You can also use the functions out-of-the-box as it were, and those examples are put first.

Clamp

Elements.Limit.clamp(number, low, high)
Limit.clamp(number, low, high)

my_bound.clamp(number)

Clamp Graph

The clamp() function returns the number but restricted between low and high

Wrap

Elements.Limit.wrap(number, low, high)
Limit.wrap(number, low, high)

my_bound.wrap(number)

Wrap Graph

The wrap() function is a modified version of the modulo (%) operator - but with one key difference:

-1 % 10 // gives -1
Limit.wrap(-1, 0, 10) // gives 9 - properly between 0 and 10

I'm thinking of doing an alternate version that swaps the upper and lower bounds, something like:

Limit.wrap(0, 0, 10) // gives 0, but
Limit.awrap(0, 0, 10) // would give 10

Fold

Elements.Limit.fold(number, low, high)
Limit.fold(number, low, high)

my_bound.fold(number)

Fold Graph

The fold() function is like wrap(), but is more continuous, and actually probably the least useful

Sigmoid

Elements.Limit.sigmoid(number, low, high)
Limit.sigmoid(number, low, high)

my_bound.sigmoid(number)

Sigmoid Graph

The sigmoid() function is a modified version of a relatively well known mathematical function, widely used as an activator function in the field of AI, I haven't actually used it yet, but I thought it'd be a bit cool to play around with it in a future project