new Foft(params)
create a Foft instance that evaluates its Function terms
when given some parameter "t".
accepts an argument params that may be a(n):
- function see params.terms for details
- object see params for details
- array of numbers see params.range for details
- Foft instance will return a copy of the instance
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
Object | function | Array.<Number> | Foft |
Properties
|
Throws:
TypeError
Examples
// returns a Foft instance let MoT = new Foft()
// returns a Foft instance that // describes an equation over the range [0,1] (inclusive) // split into 22 segments (23) total points let MoT = new Foft({ range: [0, 1], segmentDivisor: 22, terms: (t) => t*2; }); Foft also evaluates some of the properties of the Function or Foft objects in its terms
Members
-
<static> divisor :Number
-
divisor By default, Foft instances divide into
this many segmentsType:
- Number
-
<static> funcKeys
-
methods for inter-instance communication
-
<static> mathTypes
-
valid types that Foft can do math on
- Source:
- See:
-
<static> maxSafeDivisor
-
maxSafeDivisor the maximum safe to use divisor
-
<static> membKeys
-
members for inter-instance communication
-
<static> opDict
-
an array of valid op keys
-
<static> ops
-
ops an object containing operations, or ops, that
perform mathematical functions corresponding to their keys- Source:
- See:
-
<static> R
-
dimensional labeling
-
<static> sweep :Array.<Number>
-
sweep By default, Foft instances evaluate functions over this range
Type:
- Array.<Number>
-
dabsrange
-
the absolute value of the delta
between the first and final values of the evaluation range -
drange
-
the delta between the the first and final values of the evaluation range
-
dt
-
get the delta for t between the first and final values of the
evaluation range. May be innacurate when the range has more than two
terms -
numSegments
-
The number of actual segments the Foft divides the evaluation range into
-
ofAlltT
-
get a Generator that yields
all Array=[t, this.oft(t)] for t in evaluation range
in form [t, this.oft(t)] -
ofAlltTOp
-
get a Generator that yields all
this.oftOp(_t, _acc, _op) for _t in T,
_acc, _op provided by user -
ofFirstt
-
return the oft for the first t in the evaluation range
-
ofLastt
-
return the oft for the final t in the evaluation range
-
opcode
-
a Foft can have an opcode as defined in
Foft.ops. These codes represent mathematical operations
between Numbers and other types. They are useful for performing
said operations when the Function or Foft in the terms
Array -
opcode
-
set opcode - set the opcode to one of the opcodes
defined in Foft.ops -
range
-
set range - only accepts an arraylike of calculables
-
range
-
get the evaluation range is the minimum and maximum values for t
-
segmentDivisor
-
set segmentDivisor - set the segment divisor for the evaluation range where
- the range will be divided into (segmentDivisor+1) segments,
- if given an arraylike parameter, use the 0th value
- if given a calculable parameter, use it as-is
-
segmentDivisor
-
get segmentDivisor The number of segment divisors
(number of t evaluation points -1)
in this Foft -
T
-
get a Generator yielding all values of t across instance evaluation range
Example
// get the default t values for which a Foft is // evaluated let MoT = new Foft({ range: [0, Math.PI*2], segmentDivisor: 22, terms: (t) => [sin(t), cos(t)]; }); let T = [...MoT.T()]
-
t0
-
get the first value of t in the evaluation range T
-
terms
-
the Function terms of this Foft object
-
tt
-
the last value of t in the evaluation range T
Methods
-
<static> antiNormToRange( [t] [, TT])
-
given a Number t, amd a ramge TT, return a normalized (to Foft.sweep)
representation of the ratio between the two deltas A and B where- A is the difference betewen t and TT[last]
- B is the difference between TT[last] and TT[first]
If t falls out of bounds of range, the value is returned as -/+ Infinity,
where:- +Infinity corresponding to beyond the bound of TT[first], and
- -Infinity corresponding to beyond the bound of TT[last]
Parameters:
Name Type Argument Default Description t
number <optional>
0 the t to evaluate
TT
Array.<number> <optional>
sweep the range in which to test for TT
Returns:
- Type
- number
-
<static> areCalculables()
-
areCalculables return true IFF one of these conditions are met
- The provided arguments are ALL of Number type,
- The sole provided argument is an Array whose members are ALL of Number type,
- Any provided argument is an Array whose members are
A. ALL of Number type, or
B. nested Arrays whose submembers are all number types or Array,
and ALL other arguments are Number type or Array with ALL members of Number type, and - All arguments of number type are neither NaN nor -/+Infinity
Returns:
- Type
- boolean
-
<static> areNums()
-
areNums return true IFF one of these conditions are met
- The provided arguments are ALL of Number type,
- The sole provided argument is an Array whose members are ALL of Number type,
- Any provided argument is an Array whose members are
A. ALL of Number type, or
B. nested Arrays whose submembers are all number types or Arrays
and ALL other arguments are Number type or Array with ALL members of Number type,
Returns:
- Type
- boolean
-
<static> dimensions(x)
-
return the size of the given x, where x can be a number or an arraylike or a nested arraylike
Parameters:
Name Type Description x
number | Array the structure to get dimensions of
Returns:
- Type
- Array
-
<static> equiv()
-
determine whether the given number or Array-like arguments are satisfying the conditions:
- all of a single shared type,
- if numbers, of equal value,
- if arrays, composed of equal positional elements
- if other types, satisfying strict equality test
When comparing values that are NaN or containing NaN in the same positions, the function will return false because NaN doesn't equal NaN
Returns:
- Type
- boolean
-
<static> iInRange(t, TT, d)
-
given a number t, a range TT and a divisor d, return the value of the corresponding i such that
- i is proportional to the location of t within the range
- i is proportional to d
Parameters:
Name Type Description t
number t to find in TT
TT
Array.<number> range
d
type divisor
Returns:
- Type
- null | number
-
<static> inRange(n [, m] [, mm])
-
determine whether a given number n falls
within any of the follwoing inclusive ranges
0. [ Foft.sweep[0], Foft.sweep[1] ]- [0, m],
- [0, m[0]], (when provided unit-length array)
- [m[0], m[m.length-1]]
4, [m, mm]
Parameters:
Name Type Argument Description n
Number the number to test
m
Number | Array.<Number> <optional>
the end of the range starting with 0, or
the Array representing the range [m[0], m[last]]
the begining of range ending in mm, ormm
Number <optional>
the optional end of the range
Returns:
- Type
- boolean
-
<static> isArrayLike(x)
-
determine whether a given argument x is "like" an array for the purposees of Foft calculations and parsing, returning true IFF x satisfies one of the following conditions:
1 - It is an Array
2 - It is a TypedArray
3 - It provides a Symbol.iterator propertyThe third condition allows for the parsing of various iterable objects, but it does not guarantee that such actions will produce calculable values.
Parameters:
Name Type Description x
? Returns:
- Type
- boolean
-
<static> isCalculable()
-
return true IFF all of the following conditions are met
- argument satisfies isNum (One Number argument)
- argument is not NaN
- argument is not +/-Infinity
This function does more calls than just using isFinite, however, it is used in the Foft class because the class also deals with arrays and objects.
Returns:
description
- Type
- boolean
-
<static> isNum()
-
return true IFF both of the following conditions are met
- there was ONE argument provided, and
- the sole provided argument was a Number
Returns:
- Type
- boolean
-
<static> isOp(codeToParse)
-
given a string codeToParse, return true when code is found
in Foft.opDictParameters:
Name Type Description codeToParse
string - Source:
- See:
Returns:
- Type
- boolean
-
<static> mathTypeOf( [a])
-
tell whether the given argument a is of one of the types that Foft can do math with and if so, which type
Parameters:
Name Type Argument Description a
? <optional>
Returns:
- Type
- Symbol | null
-
<static> normToRange( [t] [, TT] [, NN])
-
given a Number t, amd a ramge TT, return a normalized (to an optional range NN or Foft.sweep)
representation of the ratio between the two deltas A and B where- A is the difference betewen t and TT[first]
- B is the difference between TT[last] and TT[first]
If t falls out of bounds of range, the value is returned as -/+ Infinity,
where:- -Infinity corresponding to beyond the bound of TT[first], and
- +Infinity corresponding to beyond the bound of TT[last]
Parameters:
Name Type Argument Default Description t
number <optional>
0 the t to evaluate
TT
Array.<number> <optional>
sweep the range in which to test for TT
NN
Array.<number> <optional>
sweep the target normalization range * @return {number}
-
<static> opParse(codeToParse)
-
given a string codeToParse, return
the corresponding operation function from Foft.opsParameters:
Name Type Description codeToParse
string Returns:
Foft.ops function corresponding to op
- Type
- function
-
<static> precision()
-
give precision warning in the form of an object that can be converted to a primitive.
Floating point math has inherent imprecisions. This function is for examining them.
Returns:
the object with primitive values:
{number} the maximum value for which no precision is lost
{string} as brief message- Type
- object
-
<static> tThis(t, foft)
-
given a t and a Foft instance, produces an object with some keys for inter-instance communication corresponding to:
1 the result of evaluating certain methods of the calling instance for t @see funcKeys
2 certain members of the calling instance @see membKeysParameters:
Name Type Description t
Number the t of the instance communicatiing
foft
Foft the instance doing communication
Returns:
communication object, or array of communication keys
- Type
- object | Array.<string>
-
addTerm(term [, harmonize])
-
add a term to the terms of this Foft instance
Parameters:
Name Type Argument Default Description term
function | Foft A Function that takes a parameter (t) or
Foftharmonize
boolean <optional>
false if true, and term is a Foft
instance, this overwrites the range and segmentDivisor of term to make them
reference the same-named parameters of this instance.Returns:
true if length of terms grew
- Type
- boolean
-
antinormalizeT(t)
-
given a number t return a normalized representation of the ratio of a quantity n to the delta of the instance evaluation range such that the ratio of t to the delta of the evaluation range N satisfies
1.n = maximum normal - NThis is the remaining range for the normalized value provided by normalizeT
if t falls beyond the lower bound of the evaluation range, return +Infinity
if t falls beyond the upper bound of the evaluation range, return -InfinityParameters:
Name Type Description t
number Returns:
n
- Type
- number
-
dSubrange( [n] [, nn])
-
given indices n & nn
returns the delta between sub values in the Foft instance's
evaluation range, or: range[nn%range.length]-range[n%range.length],when given no parameters, it uses 0 and 1
Parameters:
Name Type Argument Default Description n
Number <optional>
0 the starting range index.
nn
Number <optional>
n+1%this.range.length the end range index
Throws:
-
when given non-number parameter
- Type
- TypeError
Returns:
- Type
- Number
-
-
i(t)
-
given a Number t within a the evaluation range of this instance
(inclusive), return the value of the corresponding i such that- i is proportional to the location of t within the range
- i is scaled to segmentDivisor
If t falls out of bounds of the range, nothing is returned
If the range has more than two elements, return an array of length range-1
Parameters:
Name Type Description t
Number Returns:
[0, segmentDivisor]
- Type
- Number | null | Array.<(number|null)>
-
isInRange(t)
-
return true IFF a given t falls within the evaluation range of this instance
Parameters:
Name Type Description t
number Returns:
- Type
- boolean
-
mapT( [callback] [, thisArg])
-
apply the Array.map native function to the elements yielded by
this[Symbol.iterator] with the given callback function and this argument
*Parameters:
Name Type Argument Description callback
function <optional>
callback to apply
thisArg
Object <optional>
this argument
Returns:
map result
- Type
- Array
-
mapTOp( [callback] [, thisArg])
-
apply the Array.map native function to the elements of
this.ofAllTOp() with the given callback function and this argumentParameters:
Name Type Argument Description callback
function <optional>
callback to apply
thisArg
Object <optional>
this argument
Returns:
map result
- Type
- Array
-
normalizeT( [t] [, doAnti])
-
given a Number t, return a normalized (to Foft.sweep)
representation of the ratio between t and the delta of the evaluation
range of this FoftIf t falls out of bounds of range, the value is returned as -/+ Infinity
If the evaluation range has more than two values, e.g. [0,1,2],
then normalizeT checks in each subrange, e.g. [0,1], [1,2]
and returns an Array of normalized values corresponding to each rangeParameters:
Name Type Argument Default Description t
Number <optional>
0 doAnti
boolean <optional>
false Returns:
- Type
- Number | Array.<Number>
-
oft( [t] [, filterNulls] [, maketthis])
-
evaluate all of the terms held by this Mathoft for the
given t value.When evaluating a Function or Foft term, the function or Foft is called with a this object containing certain useful data regarding the calling instance's evaluation of t @see tThis
When evaluating a Foft term, any t that falls outside that term's evaluation range will produce a null result. If the filterNulls parameter is true, then null values will be stripped from the returned result.
Parameters:
Name Type Argument Default Description t
Number <optional>
t0 filterNulls
boolean <optional>
false maketthis
boolean <optional>
true Returns:
- Type
- Number | Array.<Number> | Array.<Array>
-
oftNormal( [tNormal])
-
Accepts a Number tNormal that falls within Foft.sweep, inclusive, and when provided
1 . A NaN value, return NaN
2. +Infinity, returns evaluation from end bound of range
3. -Infinity, returns evaluation from start bound of range
4. Any other number even outside of normal range, returns value of that t.Parameters:
Name Type Argument Default Description tNormal
Number <optional>
[-1,1] Returns:
- Type
- Number | Array.<Number>
-
oftOp(t [, _op] [, _acc])
-
Calculate the value of performing an operation _op on the
values returned by calculating this Foft instance's terms for
some evaluation value t. When given a parameter _acc, the calculation of _op will use _acc as its starting value.This is intended to facilitate convenient manipulation of terms and results.
Parameters:
Name Type Argument Default Description t
Number the t to evaluate
_op
string <optional>
this.opcode an opcode to perform @see Foft.ops
_acc
Number | Array.<Number> | Array.<Array> <optional>
null an accumulator value to start with @see Foft.ops -> base
Returns:
- Type
- Number | Array.<Number> | Array.<Array>
-
subT( [n])
-
get a generator function that yields segmentDivisor+1 values of t spanning the range [this.range[n], this.range[n+1]], where if n or n+1 fall beyond the bounds of this.range.length, they are constrained to fit
Parameters:
Name Type Argument Default Description n
Number <optional>
0 integer start index of range
Returns:
description
- Type
- type
-
toString()
-
toString
Returns:
- Type
- string