code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
Scheduler = function Scheduler( element, options ) { var self = this; this.$element = $( element ); this.options = $.extend( {}, $.fn.scheduler.defaults, options ); // cache elements this.$startDate = this.$element.find( '.start-datetime .start-date' ); this.$startTime = this.$element.find( '.start-...
setValue() sets the Placard triggering DOM element's display value @param {String} the value to be displayed @param {Boolean} If you want to explicitly suppress the application of ellipsis, pass `true`. This would typically only be done from internal functions (like `applyEllipsis`) that want to avoid c...
Scheduler
javascript
ExactTarget/fuelux
reference/dist/js/fuelux.js
https://github.com/ExactTarget/fuelux/blob/master/reference/dist/js/fuelux.js
BSD-3-Clause
_getFormattedDate = function _getFormattedDate( dateObj, dash ) { var fdate = ''; var item; fdate += dateObj.getFullYear(); fdate += dash; item = dateObj.getMonth() + 1; //because 0 indexing makes sense when dealing with months /sarcasm fdate += ( item < 10 ) ? '0' + item : item; fdate += dash; ...
setValue() sets the Placard triggering DOM element's display value @param {String} the value to be displayed @param {Boolean} If you want to explicitly suppress the application of ellipsis, pass `true`. This would typically only be done from internal functions (like `applyEllipsis`) that want to avoid c...
_getFormattedDate
javascript
ExactTarget/fuelux
reference/dist/js/fuelux.js
https://github.com/ExactTarget/fuelux/blob/master/reference/dist/js/fuelux.js
BSD-3-Clause
_incrementDate = function _incrementDate( start, end, interval, increment ) { return new Date( start.getTime() + ( INTERVALS[ interval ] * increment ) ); }
setValue() sets the Placard triggering DOM element's display value @param {String} the value to be displayed @param {Boolean} If you want to explicitly suppress the application of ellipsis, pass `true`. This would typically only be done from internal functions (like `applyEllipsis`) that want to avoid c...
_incrementDate
javascript
ExactTarget/fuelux
reference/dist/js/fuelux.js
https://github.com/ExactTarget/fuelux/blob/master/reference/dist/js/fuelux.js
BSD-3-Clause
function z( n ) { return ( n < 10 ? '0' : '' ) + n; }
setValue() sets the Placard triggering DOM element's display value @param {String} the value to be displayed @param {Boolean} If you want to explicitly suppress the application of ellipsis, pass `true`. This would typically only be done from internal functions (like `applyEllipsis`) that want to avoid c...
z
javascript
ExactTarget/fuelux
reference/dist/js/fuelux.js
https://github.com/ExactTarget/fuelux/blob/master/reference/dist/js/fuelux.js
BSD-3-Clause
Picker = function Picker( element, options ) { var self = this; this.$element = $( element ); this.options = $.extend( {}, $.fn.picker.defaults, options ); this.$accept = this.$element.find( '.picker-accept' ); this.$cancel = this.$element.find( '.picker-cancel' ); this.$trigger = this.$element.find(...
setValue() sets the Placard triggering DOM element's display value @param {String} the value to be displayed @param {Boolean} If you want to explicitly suppress the application of ellipsis, pass `true`. This would typically only be done from internal functions (like `applyEllipsis`) that want to avoid c...
Picker
javascript
ExactTarget/fuelux
reference/dist/js/fuelux.js
https://github.com/ExactTarget/fuelux/blob/master/reference/dist/js/fuelux.js
BSD-3-Clause
_isOffscreen = function _isOffscreen( picker ) { var windowHeight = Math.max( document.documentElement.clientHeight, window.innerHeight || 0 ); var scrollTop = $( document ).scrollTop(); var popupTop = picker.$popup.offset(); var popupBottom = popupTop.top + picker.$popup.outerHeight( true ); //if the b...
setValue() sets the Placard triggering DOM element's display value @param {String} the value to be displayed @param {Boolean} If you want to explicitly suppress the application of ellipsis, pass `true`. This would typically only be done from internal functions (like `applyEllipsis`) that want to avoid c...
_isOffscreen
javascript
ExactTarget/fuelux
reference/dist/js/fuelux.js
https://github.com/ExactTarget/fuelux/blob/master/reference/dist/js/fuelux.js
BSD-3-Clause
_display = function _display( picker ) { picker.$popup.css( 'visibility', 'hidden' ); _showBelow( picker ); //if part of the popup is offscreen try to show it above if ( _isOffscreen( picker ) ) { _showAbove( picker ); //if part of the popup is still offscreen, prefer cutting off the bottom i...
setValue() sets the Placard triggering DOM element's display value @param {String} the value to be displayed @param {Boolean} If you want to explicitly suppress the application of ellipsis, pass `true`. This would typically only be done from internal functions (like `applyEllipsis`) that want to avoid c...
_display
javascript
ExactTarget/fuelux
reference/dist/js/fuelux.js
https://github.com/ExactTarget/fuelux/blob/master/reference/dist/js/fuelux.js
BSD-3-Clause
_showAbove = function _showAbove( picker ) { picker.$popup.css( 'top', -picker.$popup.outerHeight( true ) + 'px' ); }
setValue() sets the Placard triggering DOM element's display value @param {String} the value to be displayed @param {Boolean} If you want to explicitly suppress the application of ellipsis, pass `true`. This would typically only be done from internal functions (like `applyEllipsis`) that want to avoid c...
_showAbove
javascript
ExactTarget/fuelux
reference/dist/js/fuelux.js
https://github.com/ExactTarget/fuelux/blob/master/reference/dist/js/fuelux.js
BSD-3-Clause
_showBelow = function _showBelow( picker ) { picker.$popup.css( 'top', picker.$trigger.outerHeight( true ) + 'px' ); }
setValue() sets the Placard triggering DOM element's display value @param {String} the value to be displayed @param {Boolean} If you want to explicitly suppress the application of ellipsis, pass `true`. This would typically only be done from internal functions (like `applyEllipsis`) that want to avoid c...
_showBelow
javascript
ExactTarget/fuelux
reference/dist/js/fuelux.js
https://github.com/ExactTarget/fuelux/blob/master/reference/dist/js/fuelux.js
BSD-3-Clause
function _create(data, format, datatype) { // get storage format constructor var M = type.Matrix.storage(format || 'default'); // create instance return new M(data, datatype); }
Create a new Matrix with given storage format @param {Array} data @param {string} [format] @param {string} [datatype] @returns {Matrix} Returns a new Matrix @private
_create
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function size(x) { var s = []; while (Array.isArray(x)) { s.push(x.length); x = x[0]; } return s; }
Calculate the size of a multi dimensional array. This function checks the size of the first entry, it does not validate whether all dimensions match. (use function `validate` for that) @param {Array} x @Return {Number[]} size
size
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _validate(array, size, dim) { var i; var len = array.length; if (len !== size[dim]) { throw new _error_DimensionError__WEBPACK_IMPORTED_MODULE_2___default.a(len, size[dim]); } if (dim < size.length - 1) { // recursively validate each child array var dimNext = dim + 1; for (i = 0; i...
Recursively validate whether each element in a multi dimensional array has a size corresponding to the provided size array. @param {Array} array Array to be validated @param {number[]} size Array with the size of each dimension @param {number} dim Current dimension @throws DimensionError @private
_validate
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function validate(array, size) { var isScalar = size.length === 0; if (isScalar) { // scalar if (Array.isArray(array)) { throw new _error_DimensionError__WEBPACK_IMPORTED_MODULE_2___default.a(array.length, 0); } } else { // array _validate(array, size, 0); } }
Validate whether each element in a multi dimensional array has a size corresponding to the provided size array. @param {Array} array Array to be validated @param {number[]} size Array with the size of each dimension @throws DimensionError
validate
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function validateIndex(index, length) { if (!_number__WEBPACK_IMPORTED_MODULE_0___default.a.isNumber(index) || !_number__WEBPACK_IMPORTED_MODULE_0___default.a.isInteger(index)) { throw new TypeError('Index must be an integer (value: ' + index + ')'); } if (index < 0 || typeof length === 'number' && index >= ...
Test whether index is an integer number with index >= 0 and index < length when length is provided @param {number} index Zero-based index @param {number} [length] Length of the array
validateIndex
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function resize(array, size, defaultValue) { // TODO: add support for scalars, having size=[] ? // check the type of the arguments if (!Array.isArray(array) || !Array.isArray(size)) { throw new TypeError('Array expected'); } if (size.length === 0) { throw new Error('Resizing to scalar is not supporte...
Resize a multi dimensional array. The resized array is returned. @param {Array} array Array to be resized @param {Array.<number>} size Array with the size of each dimension @param {*} [defaultValue=0] Value to be filled in in new entries, zero by default. Specify for example `null`...
resize
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _resize(array, size, dim, defaultValue) { var i; var elem; var oldLen = array.length; var newLen = size[dim]; var minLen = Math.min(oldLen, newLen); // apply new length array.length = newLen; if (dim < size.length - 1) { // non-last dimension var dimNext = dim + 1; // resize existing ch...
Recursively resize a multi dimensional array @param {Array} array Array to be resized @param {number[]} size Array with the size of each dimension @param {number} dim Current dimension @param {*} [defaultValue] Value to be filled in in new entries, undefined by def...
_resize
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function reshape(array, sizes) { var flatArray = flatten(array); var newArray; function product(arr) { return arr.reduce(function (prev, curr) { return prev * curr; }); } if (!Array.isArray(array) || !Array.isArray(sizes)) { throw new TypeError('Array expected'); } if (sizes.length ==...
Re-shape a multi dimensional array to fit the specified dimensions @param {Array} array Array to be reshaped @param {Array.<number>} sizes List of sizes for each dimension @returns {Array} Array whose data has been formatted to fit the specified dimensions @throw...
reshape
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function product(arr) { return arr.reduce(function (prev, curr) { return prev * curr; }); }
Re-shape a multi dimensional array to fit the specified dimensions @param {Array} array Array to be reshaped @param {Array.<number>} sizes List of sizes for each dimension @returns {Array} Array whose data has been formatted to fit the specified dimensions @throw...
product
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _reshape(array, sizes) { // testing if there are enough elements for the requested shape var tmpArray = array; var tmpArray2; // for each dimensions starting by the last one and ignoring the first one for (var sizeIndex = sizes.length - 1; sizeIndex > 0; sizeIndex--) { var size = sizes[sizeIndex];...
Iteratively re-shape a multi dimensional array to fit the specified dimensions @param {Array} array Array to be reshaped @param {Array.<number>} sizes List of sizes for each dimension @returns {Array} Array whose data has been formatted to fit the specified dimens...
_reshape
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function squeeze(array, arraySize) { var s = arraySize || size(array); // squeeze outer dimensions while (Array.isArray(array) && array.length === 1) { array = array[0]; s.shift(); } // find the first dimension to be squeezed var dims = s.length; while (s[dims - 1] === 1) { dims--; } // sque...
Squeeze a multi dimensional array @param {Array} array @param {Array} [arraySize] @returns {Array} returns the array itself
squeeze
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _squeeze(array, dims, dim) { var i, ii; if (dim < dims) { var next = dim + 1; for (i = 0, ii = array.length; i < ii; i++) { array[i] = _squeeze(array[i], dims, next); } } else { while (Array.isArray(array)) { array = array[0]; } } return array; }
Recursively squeeze a multi dimensional array @param {Array} array @param {number} dims Required number of dimensions @param {number} dim Current dimension @returns {Array | *} Returns the squeezed array @private
_squeeze
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function unsqueeze(array, dims, outer, arraySize) { var s = arraySize || size(array); // unsqueeze outer dimensions if (outer) { for (var i = 0; i < outer; i++) { array = [array]; s.unshift(1); } } // unsqueeze inner dimensions array = _unsqueeze(array, dims, 0); while (s.length < dims...
Unsqueeze a multi dimensional array: add dimensions when missing Paramter `size` will be mutated to match the new, unqueezed matrix size. @param {Array} array @param {number} dims Desired number of dimensions of the array @param {number} [outer] Number of outer dimensions to be added @param {Array} [arraySiz...
unsqueeze
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _unsqueeze(array, dims, dim) { var i, ii; if (Array.isArray(array)) { var next = dim + 1; for (i = 0, ii = array.length; i < ii; i++) { array[i] = _unsqueeze(array[i], dims, next); } } else { for (var d = dim; d < dims; d++) { array = [array]; } } return array; }
Recursively unsqueeze a multi dimensional array @param {Array} array @param {number} dims Required number of dimensions @param {number} dim Current dimension @returns {Array | *} Returns the squeezed array @private
_unsqueeze
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function flatten(array) { if (!Array.isArray(array)) { // if not an array, return as is return array; } var flat = []; array.forEach(function callback(value) { if (Array.isArray(value)) { value.forEach(callback); // traverse through sub-arrays recursively } else { flat.push(value); ...
Flatten a multi dimensional array, put all elements in a one dimensional array @param {Array} array A multi dimensional array @return {Array} The flattened array (1 dimensional)
flatten
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function map(array, callback) { return Array.prototype.map.call(array, callback); }
A safe map @param {Array} array @param {function} callback
map
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function forEach(array, callback) { Array.prototype.forEach.call(array, callback); }
A safe forEach @param {Array} array @param {function} callback
forEach
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function filter(array, callback) { if (size(array).length !== 1) { throw new Error('Only one dimensional matrices supported'); } return Array.prototype.filter.call(array, callback); }
A safe filter @param {Array} array @param {function} callback
filter
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function filterRegExp(array, regexp) { if (size(array).length !== 1) { throw new Error('Only one dimensional matrices supported'); } return Array.prototype.filter.call(array, function (entry) { return regexp.test(entry); }); }
Filter values in a callback given a regular expression @param {Array} array @param {RegExp} regexp @return {Array} Returns the filtered array @private
filterRegExp
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function join(array, separator) { return Array.prototype.join.call(array, separator); }
A safe join @param {Array} array @param {string} separator
join
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function identify(a) { if (!Array.isArray(a)) { throw new TypeError('Array input expected'); } if (a.length === 0) { return a; } var b = []; var count = 0; b[0] = { value: a[0], identifier: 0 }; for (var i = 1; i < a.length; i++) { if (a[i] === a[i - 1]) { count++; } e...
Assign a numeric identifier to every element of a sorted array @param {Array} a An array @return {Array} An array of objects containing the original value and its identifier
identify
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function generalize(a) { if (!Array.isArray(a)) { throw new TypeError('Array input expected'); } if (a.length === 0) { return a; } var b = []; for (var i = 0; i < a.length; i++) { b.push(a[i].value); } return b; }
Remove the numeric identifier from the elements @param {array} a An array @return {array} An array of values without identifiers
generalize
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function zeros(length) { var arr = []; for (var i = 0; i < length; i++) { arr.push(0); } return arr; }
Create an array filled with zeros. @param {number} length @return {Array}
zeros
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
algorithm14 = function algorithm14(a, b, callback, inverse) { // a arrays var adata = a._data; var asize = a._size; var adt = a._datatype; // datatype var dt; // callback signature to use var cf = callback; // process data types if (typeof adt === 'string') { // datatype dt = ...
Iterates over DenseMatrix items and invokes the callback function f(Aij..z, b). Callback function invoked MxN times. C(i,j,...z) = f(Aij..z, b) @param {Matrix} a The DenseMatrix instance (A) @param {Scalar} b The Scalar value @param {Function} callback The f(Aij..z,b) oper...
algorithm14
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _iterate(f, level, s, n, av, bv, inverse) { // initialize array for this level var cv = []; // check we reach the last level if (level === s.length - 1) { // loop arrays in last level for (var i = 0; i < n; i++) { // invoke callback and store value cv[i] = inverse ? f(b...
Iterates over DenseMatrix items and invokes the callback function f(Aij..z, b). Callback function invoked MxN times. C(i,j,...z) = f(Aij..z, b) @param {Matrix} a The DenseMatrix instance (A) @param {Scalar} b The Scalar value @param {Function} callback The f(Aij..z,b) oper...
_iterate
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
algorithm13 = function algorithm13(a, b, callback) { // a arrays var adata = a._data; var asize = a._size; var adt = a._datatype; // b arrays var bdata = b._data; var bsize = b._size; var bdt = b._datatype; // c arrays var csize = []; // validate dimensions if (asize.length !== bs...
Iterates over DenseMatrix items and invokes the callback function f(Aij..z, Bij..z). Callback function invoked MxN times. C(i,j,...z) = f(Aij..z, Bij..z) @param {Matrix} a The DenseMatrix instance (A) @param {Matrix} b The DenseMatrix instance (B) @param {Function} callback ...
algorithm13
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _iterate(f, level, s, n, av, bv) { // initialize array for this level var cv = []; // check we reach the last level if (level === s.length - 1) { // loop arrays in last level for (var i = 0; i < n; i++) { // invoke callback and store value cv[i] = f(av[i], bv[i]); ...
Iterates over DenseMatrix items and invokes the callback function f(Aij..z, Bij..z). Callback function invoked MxN times. C(i,j,...z) = f(Aij..z, Bij..z) @param {Matrix} a The DenseMatrix instance (A) @param {Matrix} b The DenseMatrix instance (B) @param {Function} callback ...
_iterate
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function DimensionError(actual, expected, relation) { if (!(this instanceof DimensionError)) { throw new SyntaxError('Constructor must be called with the new operator'); } this.actual = actual; this.expected = expected; this.relation = relation; this.message = 'Dimension mismatch (' + (Array.isArray(ac...
Create a range error with the message: 'Dimension mismatch (<actual size> != <expected size>)' @param {number | number[]} actual The actual size @param {number | number[]} expected The expected size @param {string} [relation='!='] Optional relation between actual ...
DimensionError
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function formatArray(array, options) { if (Array.isArray(array)) { var str = '['; var len = array.length; for (var i = 0; i < len; i++) { if (i !== 0) { str += ', '; } str += formatArray(array[i], options); } str += ']'; return str; } else { return exports.fo...
Recursively format an n-dimensional matrix Example output: "[[1, 2], [3, 4]]" @param {Array} array @param {Object | number | Function} [options] Formatting options. See lib/utils/number:format for a description of the availab...
formatArray
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function looksLikeFraction(value) { return value && _typeof(value) === 'object' && typeof value.s === 'number' && typeof value.n === 'number' && typeof value.d === 'number' || false; }
Check whether a value looks like a Fraction (unsafe duck-type check) @param {*} value @return {boolean}
looksLikeFraction
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _validateMatrixDimensions(size1, size2) { // check left operand dimensions switch (size1.length) { case 1: // check size2 switch (size2.length) { case 1: // Vector x Vector if (size1[0] !== size2[0]) { // throw error th...
Multiply two or more values, `x * y`. For matrices, the matrix product is calculated. Syntax: math.multiply(x, y) math.multiply(x, y, z, ...) Examples: math.multiply(4, 5.2) // returns number 20.8 math.multiply(2, 3, 4) // returns number 24 const a = math.complex(2, 3) const b = math...
_validateMatrixDimensions
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _multiplyVectorVector(a, b, n) { // check empty vector if (n === 0) { throw new Error('Cannot multiply two empty vectors'); } // a dense var adata = a._data; var adt = a._datatype; // b dense var bdata = b._data; var bdt = b._datatype; // datatype var dt; // addScalar ...
C = A * B @param {Matrix} a Dense Vector (N) @param {Matrix} b Dense Vector (N) @return {number} Scalar value
_multiplyVectorVector
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _multiplyVectorMatrix(a, b) { // process storage if (b.storage() !== 'dense') { throw new Error('Support for SparseMatrix not implemented'); } return _multiplyVectorDenseMatrix(a, b); }
C = A * B @param {Matrix} a Dense Vector (M) @param {Matrix} b Matrix (MxN) @return {Matrix} Dense Vector (N)
_multiplyVectorMatrix
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _multiplyVectorDenseMatrix(a, b) { // a dense var adata = a._data; var asize = a._size; var adt = a._datatype; // b dense var bdata = b._data; var bsize = b._size; var bdt = b._datatype; // rows & columns var alength = asize[0]; var bcolumns = bsize[1]; // datatype va...
C = A * B @param {Matrix} a Dense Vector (M) @param {Matrix} b Dense Matrix (MxN) @return {Matrix} Dense Vector (N)
_multiplyVectorDenseMatrix
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _multiplyDenseMatrixVector(a, b) { // a dense var adata = a._data; var asize = a._size; var adt = a._datatype; // b dense var bdata = b._data; var bdt = b._datatype; // rows & columns var arows = asize[0]; var acolumns = asize[1]; // datatype var dt; // addScalar signatur...
C = A * B @param {Matrix} a DenseMatrix (MxN) @param {Matrix} b Dense Vector (N) @return {Matrix} Dense Vector (M)
_multiplyDenseMatrixVector
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _multiplyDenseMatrixDenseMatrix(a, b) { // a dense var adata = a._data; var asize = a._size; var adt = a._datatype; // b dense var bdata = b._data; var bsize = b._size; var bdt = b._datatype; // rows & columns var arows = asize[0]; var acolumns = asize[1]; var bcolumns...
C = A * B @param {Matrix} a DenseMatrix (MxN) @param {Matrix} b DenseMatrix (NxC) @return {Matrix} DenseMatrix (MxC)
_multiplyDenseMatrixDenseMatrix
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _multiplyDenseMatrixSparseMatrix(a, b) { // a dense var adata = a._data; var asize = a._size; var adt = a._datatype; // b sparse var bvalues = b._values; var bindex = b._index; var bptr = b._ptr; var bsize = b._size; var bdt = b._datatype; // validate b matrix if (!bva...
C = A * B @param {Matrix} a DenseMatrix (MxN) @param {Matrix} b SparseMatrix (NxC) @return {Matrix} SparseMatrix (MxC)
_multiplyDenseMatrixSparseMatrix
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _multiplySparseMatrixVector(a, b) { // a sparse var avalues = a._values; var aindex = a._index; var aptr = a._ptr; var adt = a._datatype; // validate a matrix if (!avalues) { throw new Error('Cannot multiply Pattern only Matrix times Dense Matrix'); } // b dense var bda...
C = A * B @param {Matrix} a SparseMatrix (MxN) @param {Matrix} b Dense Vector (N) @return {Matrix} SparseMatrix (M, 1)
_multiplySparseMatrixVector
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _multiplySparseMatrixDenseMatrix(a, b) { // a sparse var avalues = a._values; var aindex = a._index; var aptr = a._ptr; var adt = a._datatype; // validate a matrix if (!avalues) { throw new Error('Cannot multiply Pattern only Matrix times Dense Matrix'); } // b dense va...
C = A * B @param {Matrix} a SparseMatrix (MxN) @param {Matrix} b DenseMatrix (NxC) @return {Matrix} SparseMatrix (MxC)
_multiplySparseMatrixDenseMatrix
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _multiplySparseMatrixSparseMatrix(a, b) { // a sparse var avalues = a._values; var aindex = a._index; var aptr = a._ptr; var adt = a._datatype; // b sparse var bvalues = b._values; var bindex = b._index; var bptr = b._ptr; var bdt = b._datatype; // rows & columns var a...
C = A * B @param {Matrix} a SparseMatrix (MxN) @param {Matrix} b SparseMatrix (NxC) @return {Matrix} SparseMatrix (MxC)
_multiplySparseMatrixSparseMatrix
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function getSafeProperty(object, prop) { // only allow getting safe properties of a plain object if (isPlainObject(object) && isSafeProperty(object, prop)) { return object[prop]; } if (typeof object[prop] === 'function' && isSafeMethod(object, prop)) { throw new Error('Cannot access method "' + prop + ...
Get a property of a plain object Throws an error in case the object is not a plain object or the property is not defined on the object itself @param {Object} object @param {string} prop @return {*} Returns the property value when safe
getSafeProperty
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function setSafeProperty(object, prop, value) { // only allow setting safe properties of a plain object if (isPlainObject(object) && isSafeProperty(object, prop)) { object[prop] = value; return value; } throw new Error('No access to property "' + prop + '"'); }
Set a property on a plain object. Throws an error in case the object is not a plain object or the property would override an inherited property like .constructor or .toString @param {Object} object @param {string} prop @param {*} value @return {*} Returns the value
setSafeProperty
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function isSafeProperty(object, prop) { if (!object || _typeof(object) !== 'object') { return false; } // SAFE: whitelisted // e.g length if (hasOwnProperty(safeNativeProperties, prop)) { return true; } // UNSAFE: inherited from Object prototype // e.g constructor if (prop in Object.prototype)...
Test whether a property is safe to use for an object. For example .toString and .constructor are not safe @param {string} prop @return {boolean} Returns true when safe
isSafeProperty
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function validateSafeMethod(object, method) { if (!isSafeMethod(object, method)) { throw new Error('No access to method "' + method + '"'); } }
Validate whether a method is safe. Throws an error when that's not the case. @param {Object} object @param {string} method
validateSafeMethod
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function isSafeMethod(object, method) { if (!object || typeof object[method] !== 'function') { return false; } // UNSAFE: ghosted // e.g overridden toString // Note that IE10 doesn't support __proto__ and we can't do this check there. if (hasOwnProperty(object, method) && Object.getPrototypeOf && method...
Check whether a method is safe. Throws an error when that's not the case (for example for `constructor`). @param {Object} object @param {string} method @return {boolean} Returns true when safe, false otherwise
isSafeMethod
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function isPlainObject(object) { return _typeof(object) === 'object' && object && object.constructor === Object; }
Check whether a method is safe. Throws an error when that's not the case (for example for `constructor`). @param {Object} object @param {string} method @return {boolean} Returns true when safe, false otherwise
isPlainObject
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function checkEqualDimensions(x, y) { var xsize = x.size(); var ysize = y.size(); if (xsize.length !== ysize.length) { throw new DimensionError(xsize.length, ysize.length); } }
Check whether matrix x and y have the same number of dimensions. Throws a DimensionError when dimensions are not equal @param {Matrix} x @param {Matrix} y
checkEqualDimensions
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _traverse(node, callback) { node.forEach(function (child, path, parent) { callback(child, path, parent); _traverse(child, callback); }); }
Recursively traverse all nodes in a node tree. Executes given callback for this node and each of its child nodes. @param {function(node: Node, path: string, parent: Node)} callback A callback called for every node in the node tree.
_traverse
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _transform(node, callback) { return node.map(function (child, path, parent) { var replacement = callback(child, path, parent); return _transform(replacement, callback); }); }
Recursively transform a node tree via a transform function. For example, to replace all nodes of type SymbolNode having name 'x' with a ConstantNode with value 2: const res = Node.transform(function (node, path, parent) { if (node && node.isSymbolNode) && (node.name === 'x')) { return new ConstantNo...
_transform
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _validateScope(scope) { for (var symbol in scope) { if (hasOwnProperty(scope, symbol)) { if (symbol in keywords) { throw new Error('Scope contains an illegal symbol, "' + symbol + '" is a reserved keyword'); } } } }
Validate the symbol names of a scope. Throws an error when the scope contains an illegal symbol. @param {Object} scope
_validateScope
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _getSubstring(str, index) { if (!type.isIndex(index)) { // TODO: better error message throw new TypeError('Index expected'); } if (index.size().length !== 1) { throw new DimensionError(index.size().length, 1); } // validate whether the range is out of range var strLen =...
Retrieve a subset of a string @param {string} str string from which to get a substring @param {Index} index An index containing ranges for each dimension @returns {string} substring @private
_getSubstring
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _setSubstring(str, index, replacement, defaultValue) { if (!index || index.isIndex !== true) { // TODO: better error message throw new TypeError('Index expected'); } if (index.size().length !== 1) { throw new DimensionError(index.size().length, 1); } if (defaultValue !==...
Replace a substring in a string @param {string} str string to be replaced @param {Index} index An index containing ranges for each dimension @param {string} replacement Replacement string @param {string} [defaultValue] Default value to be uses when resizing the str...
_setSubstring
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _getObjectProperty(object, index) { if (index.size().length !== 1) { throw new DimensionError(index.size(), 1); } var key = index.dimension(0); if (typeof key !== 'string') { throw new TypeError('String expected as index to retrieve an object property'); } return getSafeProperty(object, ...
Retrieve a property from an object @param {Object} object @param {Index} index @return {*} Returns the value of the property @private
_getObjectProperty
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _setObjectProperty(object, index, replacement) { if (index.size().length !== 1) { throw new DimensionError(index.size(), 1); } var key = index.dimension(0); if (typeof key !== 'string') { throw new TypeError('String expected as index to retrieve an object property'); } // clone the object, ...
Set a property on an object @param {Object} object @param {Index} index @param {*} replacement @return {*} Returns the updated object @private
_setObjectProperty
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function Index(ranges) { if (!(this instanceof Index)) { throw new SyntaxError('Constructor must be called with the new operator'); } this._dimensions = []; this._isScalar = true; for (var i = 0, ii = arguments.length; i < ii; i++) { var arg = arguments[i]; if (type.isRange(arg)...
Create an index. An Index can store ranges and sets for multiple dimensions. Matrix.get, Matrix.set, and math.subset accept an Index as input. Usage: const index = new Index(range1, range2, matrix1, array1, ...) Where each parameter can be any of: A number A string (containing a name of an object property...
Index
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
algorithm07 = function algorithm07(a, b, callback) { // sparse matrix arrays var asize = a._size; var adt = a._datatype; // sparse matrix arrays var bsize = b._size; var bdt = b._datatype; // validate dimensions if (asize.length !== bsize.length) { throw new DimensionError(asize.length, ...
Iterates over SparseMatrix A and SparseMatrix B items (zero and nonzero) and invokes the callback function f(Aij, Bij). Callback function invoked MxN times. C(i,j) = f(Aij, Bij) @param {Matrix} a The SparseMatrix instance (A) @param {Matrix} b The SparseMatrix instance (B) @param {...
algorithm07
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _scatter(m, j, w, x, mark) { // a arrays var values = m._values; var index = m._index; var ptr = m._ptr; // loop values in column j for (var k = ptr[j], k1 = ptr[j + 1]; k < k1; k++) { // row var i = index[k]; // update workspace w[i] = mark; x[i] = values[k]; ...
Iterates over SparseMatrix A and SparseMatrix B items (zero and nonzero) and invokes the callback function f(Aij, Bij). Callback function invoked MxN times. C(i,j) = f(Aij, Bij) @param {Matrix} a The SparseMatrix instance (A) @param {Matrix} b The SparseMatrix instance (B) @param {...
_scatter
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function compareMatricesAndArrays(x, y) { if (type.isSparseMatrix(x) && type.isSparseMatrix(y)) { return compareArrays(x.toJSON().values, y.toJSON().values); } if (type.isSparseMatrix(x)) { // note: convert to array is expensive return compareMatricesAndArrays(x.toArray(), y); } ...
Compare mixed matrix/array types, by converting to same-shaped array. This comparator is non-deterministic regarding input types. @param {Array | SparseMatrix | DenseMatrix | *} x @param {Array | SparseMatrix | DenseMatrix | *} y @returns {number} Returns the comparison result: -1, 0, or 1
compareMatricesAndArrays
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function compareArrays(x, y) { // compare each value for (var i = 0, ii = Math.min(x.length, y.length); i < ii; i++) { var v = compareNatural(x[i], y[i]); if (v !== 0) { return v; } } // compare the size of the arrays if (x.length > y.length) { return 1; } if ...
Compare two Arrays - First, compares value by value - Next, if all corresponding values are equal, look at the length: longest array will be considered largest @param {Array} x @param {Array} y @returns {number} Returns the comparison result: -1, 0, or 1
compareArrays
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function compareObjects(x, y) { var keysX = Object.keys(x); var keysY = Object.keys(y); // compare keys keysX.sort(naturalSort); keysY.sort(naturalSort); var c = compareArrays(keysX, keysY); if (c !== 0) { return c; } // compare values for (var i = 0; i < keysX.length; i++) { ...
Compare two objects - First, compare sorted property names - Next, compare the property values @param {Object} x @param {Object} y @returns {number} Returns the comparison result: -1, 0, or 1
compareObjects
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function compareComplexNumbers(x, y) { if (x.re > y.re) { return 1; } if (x.re < y.re) { return -1; } if (x.im > y.im) { return 1; } if (x.im < y.im) { return -1; } return 0; }
Compare two complex numbers, `x` and `y`: - First, compare the real values of `x` and `y` - If equal, compare the imaginary values of `x` and `y` @params {Complex} x @params {Complex} y @returns {number} Returns the comparison result: -1, 0, or 1
compareComplexNumbers
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _pow(x, y) { // Alternatively could define a 'realmode' config option or something, but // 'predictable' will work for now if (config.predictable && !isInteger(y) && x < 0) { // Check to see if y can be represented as a fraction try { var yFrac = fraction(y); var yNum = ...
Calculates the power of x to y, x^y, for two numbers. @param {number} x @param {number} y @return {number | Complex} res @private
_pow
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _powArray(x, y) { if (!isInteger(y) || y < 0) { throw new TypeError('For A^b, b must be a positive integer (value is ' + y + ')'); } // verify that A is a 2 dimensional square matrix var s = size(x); if (s.length !== 2) { throw new Error('For A^b, A must be 2 dimensional (A has '...
Calculate the power of a 2d array @param {Array} x must be a 2 dimensional, square matrix @param {number} y a positive, integer value @returns {Array} @private
_powArray
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _powMatrix(x, y) { return matrix(_powArray(x.valueOf(), y)); }
Calculate the power of a 2d matrix @param {Matrix} x must be a 2 dimensional, square matrix @param {number} y a positive, integer value @returns {Matrix} @private
_powMatrix
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _zeros(size, format) { var hasBigNumbers = _normalize(size); var defaultValue = hasBigNumbers ? new type.BigNumber(0) : 0; _validate(size); if (format) { // return a matrix var m = matrix(format); if (size.length > 0) { return m.resize(size, defaultValue); } ...
Create an Array or Matrix with zeros @param {Array} size @param {string} [format='default'] @return {Array | Matrix} @private
_zeros
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _normalize(size) { var hasBigNumbers = false; size.forEach(function (value, index, arr) { if (type.isBigNumber(value)) { hasBigNumbers = true; arr[index] = value.toNumber(); } }); return hasBigNumbers; } // validate arguments
Create an Array or Matrix with zeros @param {Array} size @param {string} [format='default'] @return {Array | Matrix} @private
_normalize
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function _validate(size) { size.forEach(function (value) { if (typeof value !== 'number' || !isInteger(value) || value < 0) { throw new Error('Parameters in function zeros must be positive integers'); } }); }
Create an Array or Matrix with zeros @param {Array} size @param {string} [format='default'] @return {Array | Matrix} @private
_validate
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function parse(expr, options) { if (arguments.length !== 1 && arguments.length !== 2) { throw new ArgumentsError('parse', arguments.length, 1, 2); } // pass extra nodes var extraNodes = options && options.nodes ? options.nodes : {}; if (typeof expr === 'string') { // parse a single expres...
Parse an expression. Returns a node tree, which can be evaluated by invoking node.eval(). Syntax: parse(expr) parse(expr, options) parse([expr1, expr2, expr3, ...]) parse([expr1, expr2, expr3, ...], options) Example: const node = parse('sqrt(3^2 + 4^2)') node.compile(math).eval() // 5 l...
parse
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function initialState() { return { extraNodes: {}, // current extra nodes, must be careful not to mutate expression: '', // current expression comment: '', // last parsed comment index: 0, // current index in expr token: '', // current token tokenTyp...
Parse an expression. Returns a node tree, which can be evaluated by invoking node.eval(). Syntax: parse(expr) parse(expr, options) parse([expr1, expr2, expr3, ...]) parse([expr1, expr2, expr3, ...], options) Example: const node = parse('sqrt(3^2 + 4^2)') node.compile(math).eval() // 5 l...
initialState
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function currentString(state, length) { return state.expression.substr(state.index, length); }
View upto `length` characters of the expression starting at the current character. @param {State} state @param {number} [length=1] Number of characters to view @returns {string} @private
currentString
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function currentCharacter(state) { return currentString(state, 1); }
View the current character. Returns '' if end of expression is reached. @param {State} state @returns {string} @private
currentCharacter
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function prevCharacter(state) { return state.expression.charAt(state.index - 1); }
Preview the previous character from the expression. @return {string} cNext @private
prevCharacter
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function nextCharacter(state) { return state.expression.charAt(state.index + 1); }
Preview the next character from the expression. @return {string} cNext @private
nextCharacter
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function getToken(state) { state.tokenType = TOKENTYPE.NULL; state.token = ''; state.comment = ''; // skip over whitespaces // space, tab, and newline when inside parameters while (parse.isWhitespace(currentCharacter(state), state.nestingLevel)) { next(state); } // skip comment if (...
Get next token in the current string expr. The token and token type are available as token and tokenType @private
getToken
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function getTokenSkipNewline(state) { do { getToken(state); } while (state.token === '\n'); // eslint-disable-line no-unmodified-loop-condition }
Get next token and skip newline tokens
getTokenSkipNewline
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function parseStart(expression, extraNodes) { var state = initialState(); _extends(state, { expression: expression, extraNodes: extraNodes }); getToken(state); var node = parseBlock(state); // check for garbage at the end of the expression // an expression ends with a empty charact...
Start of the parse levels below, in order of precedence @return {Node} node @private
parseStart
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function parseBlock(state) { var node; var blocks = []; var visible; if (state.token !== '' && state.token !== '\n' && state.token !== ';') { node = parseAssignment(state); node.comment = state.comment; } // TODO: simplify this loop while (state.token === '\n' || state.token === '...
Parse a block with expressions. Expressions can be separated by a newline character '\n', or by a semicolon ';'. In case of a semicolon, no output of the preceding line is returned. @return {Node} node @private
parseBlock
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function parseAssignment(state) { var name, args, value, valid; var node = parseConditional(state); if (state.token === '=') { if (type.isSymbolNode(node)) { // parse a variable assignment like 'a = 2/3' name = node.name; getTokenSkipNewline(state); value = parseAssign...
Assignment of a function or variable, - can be a variable like 'a=2.3' - or a updating an existing variable like 'matrix(2,3:5)=[6,7,8]' - defining a function like 'f(x) = x^2' @return {Node} node @private
parseAssignment
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function parseConditional(state) { var node = parseLogicalOr(state); while (state.token === '?') { // eslint-disable-line no-unmodified-loop-condition // set a conditional level, the range operator will be ignored as long // as conditionalLevel === state.nestingLevel. var prev = state.c...
conditional operation condition ? truePart : falsePart Note: conditional operator is right-associative @return {Node} node @private
parseConditional
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function parseLogicalOr(state) { var node = parseLogicalXor(state); while (state.token === 'or') { // eslint-disable-line no-unmodified-loop-condition getTokenSkipNewline(state); node = new OperatorNode('or', 'or', [node, parseLogicalXor(state)]); } return node; }
logical or, 'x or y' @return {Node} node @private
parseLogicalOr
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function parseLogicalXor(state) { var node = parseLogicalAnd(state); while (state.token === 'xor') { // eslint-disable-line no-unmodified-loop-condition getTokenSkipNewline(state); node = new OperatorNode('xor', 'xor', [node, parseLogicalAnd(state)]); } return node; }
logical exclusive or, 'x xor y' @return {Node} node @private
parseLogicalXor
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function parseLogicalAnd(state) { var node = parseBitwiseOr(state); while (state.token === 'and') { // eslint-disable-line no-unmodified-loop-condition getTokenSkipNewline(state); node = new OperatorNode('and', 'and', [node, parseBitwiseOr(state)]); } return node; }
logical and, 'x and y' @return {Node} node @private
parseLogicalAnd
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function parseBitwiseOr(state) { var node = parseBitwiseXor(state); while (state.token === '|') { // eslint-disable-line no-unmodified-loop-condition getTokenSkipNewline(state); node = new OperatorNode('|', 'bitOr', [node, parseBitwiseXor(state)]); } return node; }
bitwise or, 'x | y' @return {Node} node @private
parseBitwiseOr
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function parseBitwiseXor(state) { var node = parseBitwiseAnd(state); while (state.token === '^|') { // eslint-disable-line no-unmodified-loop-condition getTokenSkipNewline(state); node = new OperatorNode('^|', 'bitXor', [node, parseBitwiseAnd(state)]); } return node; }
bitwise exclusive or (xor), 'x ^| y' @return {Node} node @private
parseBitwiseXor
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function parseBitwiseAnd(state) { var node = parseRelational(state); while (state.token === '&') { // eslint-disable-line no-unmodified-loop-condition getTokenSkipNewline(state); node = new OperatorNode('&', 'bitAnd', [node, parseRelational(state)]); } return node; }
bitwise and, 'x & y' @return {Node} node @private
parseBitwiseAnd
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function parseRelational(state) { var params = [parseShift(state)]; var conditionals = []; var operators = { '==': 'equal', '!=': 'unequal', '<': 'smaller', '>': 'larger', '<=': 'smallerEq', '>=': 'largerEq' }; while (operators.hasOwnProperty(state.token)) { ...
Parse a chained conditional, like 'a > b >= c' @return {Node} node
parseRelational
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function parseShift(state) { var node, operators, name, fn, params; node = parseConversion(state); operators = { '<<': 'leftShift', '>>': 'rightArithShift', '>>>': 'rightLogShift' }; while (operators.hasOwnProperty(state.token)) { name = state.token; fn = operators[nam...
Bitwise left shift, bitwise right arithmetic shift, bitwise right logical shift @return {Node} node @private
parseShift
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function parseConversion(state) { var node, operators, name, fn, params; node = parseRange(state); operators = { 'to': 'to', 'in': 'to' // alias of 'to' }; while (operators.hasOwnProperty(state.token)) { name = state.token; fn = operators[name]; getTokenSkipNewline(st...
conversion operators 'to' and 'in' @return {Node} node @private
parseConversion
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function parseRange(state) { var node; var params = []; if (state.token === ':') { // implicit start=1 (one-based) node = new ConstantNode(1); } else { // explicit start node = parseAddSubtract(state); } if (state.token === ':' && state.conditionalLevel !== state.nestin...
parse range, "start:end", "start:step:end", ":", "start:", ":end", etc @return {Node} node @private
parseRange
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function parseAddSubtract(state) { var node, operators, name, fn, params; node = parseMultiplyDivide(state); operators = { '+': 'add', '-': 'subtract' }; while (operators.hasOwnProperty(state.token)) { name = state.token; fn = operators[name]; getTokenSkipNewline(state...
add or subtract @return {Node} node @private
parseAddSubtract
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT
function parseMultiplyDivide(state) { var node, last, operators, name, fn; node = parseImplicitMultiplication(state); last = node; operators = { '*': 'multiply', '.*': 'dotMultiply', '/': 'divide', './': 'dotDivide', '%': 'mod', 'mod': 'mod' }; while (true) {...
multiply, divide, modulus @return {Node} node @private
parseMultiplyDivide
javascript
grimalschi/calque
math.js
https://github.com/grimalschi/calque/blob/master/math.js
MIT