UNPKG

plotly.js

Version:

The open source javascript graphing library that powers plotly

1,917 lines (1,618 loc) 3.83 MB
/** * plotly.js (gl3d) v1.58.4 * Copyright 2012-2020, Plotly, Inc. * All rights reserved. * Licensed under the MIT license */ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Plotly = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(_dereq_,module,exports){ 'use strict'; var Lib = _dereq_('../src/lib'); var rules = { "X,X div": "direction:ltr;font-family:'Open Sans', verdana, arial, sans-serif;margin:0;padding:0;", "X input,X button": "font-family:'Open Sans', verdana, arial, sans-serif;", "X input:focus,X button:focus": "outline:none;", "X a": "text-decoration:none;", "X a:hover": "text-decoration:none;", "X .crisp": "shape-rendering:crispEdges;", "X .user-select-none": "-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none;", "X svg": "overflow:hidden;", "X svg a": "fill:#447adb;", "X svg a:hover": "fill:#3c6dc5;", "X .main-svg": "position:absolute;top:0;left:0;pointer-events:none;", "X .main-svg .draglayer": "pointer-events:all;", "X .cursor-default": "cursor:default;", "X .cursor-pointer": "cursor:pointer;", "X .cursor-crosshair": "cursor:crosshair;", "X .cursor-move": "cursor:move;", "X .cursor-col-resize": "cursor:col-resize;", "X .cursor-row-resize": "cursor:row-resize;", "X .cursor-ns-resize": "cursor:ns-resize;", "X .cursor-ew-resize": "cursor:ew-resize;", "X .cursor-sw-resize": "cursor:sw-resize;", "X .cursor-s-resize": "cursor:s-resize;", "X .cursor-se-resize": "cursor:se-resize;", "X .cursor-w-resize": "cursor:w-resize;", "X .cursor-e-resize": "cursor:e-resize;", "X .cursor-nw-resize": "cursor:nw-resize;", "X .cursor-n-resize": "cursor:n-resize;", "X .cursor-ne-resize": "cursor:ne-resize;", "X .cursor-grab": "cursor:-webkit-grab;cursor:grab;", "X .modebar": "position:absolute;top:2px;right:2px;", "X .ease-bg": "-webkit-transition:background-color 0.3s ease 0s;-moz-transition:background-color 0.3s ease 0s;-ms-transition:background-color 0.3s ease 0s;-o-transition:background-color 0.3s ease 0s;transition:background-color 0.3s ease 0s;", "X .modebar--hover>:not(.watermark)": "opacity:0;-webkit-transition:opacity 0.3s ease 0s;-moz-transition:opacity 0.3s ease 0s;-ms-transition:opacity 0.3s ease 0s;-o-transition:opacity 0.3s ease 0s;transition:opacity 0.3s ease 0s;", "X:hover .modebar--hover .modebar-group": "opacity:1;", "X .modebar-group": "float:left;display:inline-block;box-sizing:border-box;padding-left:8px;position:relative;vertical-align:middle;white-space:nowrap;", "X .modebar-btn": "position:relative;font-size:16px;padding:3px 4px;height:22px;cursor:pointer;line-height:normal;box-sizing:border-box;", "X .modebar-btn svg": "position:relative;top:2px;", "X .modebar.vertical": "display:flex;flex-direction:column;flex-wrap:wrap;align-content:flex-end;max-height:100%;", "X .modebar.vertical svg": "top:-1px;", "X .modebar.vertical .modebar-group": "display:block;float:none;padding-left:0px;padding-bottom:8px;", "X .modebar.vertical .modebar-group .modebar-btn": "display:block;text-align:center;", "X [data-title]:before,X [data-title]:after": "position:absolute;-webkit-transform:translate3d(0, 0, 0);-moz-transform:translate3d(0, 0, 0);-ms-transform:translate3d(0, 0, 0);-o-transform:translate3d(0, 0, 0);transform:translate3d(0, 0, 0);display:none;opacity:0;z-index:1001;pointer-events:none;top:110%;right:50%;", "X [data-title]:hover:before,X [data-title]:hover:after": "display:block;opacity:1;", "X [data-title]:before": "content:'';position:absolute;background:transparent;border:6px solid transparent;z-index:1002;margin-top:-12px;border-bottom-color:#69738a;margin-right:-6px;", "X [data-title]:after": "content:attr(data-title);background:#69738a;color:white;padding:8px 10px;font-size:12px;line-height:12px;white-space:nowrap;margin-right:-18px;border-radius:2px;", "X .vertical [data-title]:before,X .vertical [data-title]:after": "top:0%;right:200%;", "X .vertical [data-title]:before": "border:6px solid transparent;border-left-color:#69738a;margin-top:8px;margin-right:-30px;", "X .select-outline": "fill:none;stroke-width:1;shape-rendering:crispEdges;", "X .select-outline-1": "stroke:white;", "X .select-outline-2": "stroke:black;stroke-dasharray:2px 2px;", Y: "font-family:'Open Sans', verdana, arial, sans-serif;position:fixed;top:50px;right:20px;z-index:10000;font-size:10pt;max-width:180px;", "Y p": "margin:0;", "Y .notifier-note": "min-width:180px;max-width:250px;border:1px solid #fff;z-index:3000;margin:0;background-color:#8c97af;background-color:rgba(140,151,175,0.9);color:#fff;padding:10px;overflow-wrap:break-word;word-wrap:break-word;-ms-hyphens:auto;-webkit-hyphens:auto;hyphens:auto;", "Y .notifier-close": "color:#fff;opacity:0.8;float:right;padding:0 5px;background:none;border:none;font-size:20px;font-weight:bold;line-height:20px;", "Y .notifier-close:hover": "color:#444;text-decoration:none;cursor:pointer;" }; for(var selector in rules) { var fullSelector = selector.replace(/^,/,' ,') .replace(/X/g, '.js-plotly-plot .plotly') .replace(/Y/g, '.plotly-notifier'); Lib.addStyleRule(fullSelector, rules[selector]); } },{"../src/lib":524}],2:[function(_dereq_,module,exports){ /** * Copyright 2012-2020, Plotly, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; module.exports = _dereq_('../src/traces/cone'); },{"../src/traces/cone":639}],3:[function(_dereq_,module,exports){ /** * Copyright 2012-2020, Plotly, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; module.exports = _dereq_('../src/core'); },{"../src/core":504}],4:[function(_dereq_,module,exports){ /** * Copyright 2012-2020, Plotly, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; var Plotly = _dereq_('./core'); Plotly.register([ _dereq_('./scatter3d'), _dereq_('./surface'), _dereq_('./mesh3d'), _dereq_('./isosurface'), _dereq_('./volume'), _dereq_('./cone'), _dereq_('./streamtube') ]); module.exports = Plotly; },{"./cone":2,"./core":3,"./isosurface":5,"./mesh3d":6,"./scatter3d":7,"./streamtube":8,"./surface":9,"./volume":10}],5:[function(_dereq_,module,exports){ /** * Copyright 2012-2020, Plotly, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; module.exports = _dereq_('../src/traces/isosurface'); },{"../src/traces/isosurface":646}],6:[function(_dereq_,module,exports){ /** * Copyright 2012-2020, Plotly, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; module.exports = _dereq_('../src/traces/mesh3d'); },{"../src/traces/mesh3d":651}],7:[function(_dereq_,module,exports){ /** * Copyright 2012-2020, Plotly, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; module.exports = _dereq_('../src/traces/scatter3d'); },{"../src/traces/scatter3d":688}],8:[function(_dereq_,module,exports){ /** * Copyright 2012-2020, Plotly, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; module.exports = _dereq_('../src/traces/streamtube'); },{"../src/traces/streamtube":693}],9:[function(_dereq_,module,exports){ /** * Copyright 2012-2020, Plotly, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; module.exports = _dereq_('../src/traces/surface'); },{"../src/traces/surface":698}],10:[function(_dereq_,module,exports){ /** * Copyright 2012-2020, Plotly, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; module.exports = _dereq_('../src/traces/volume'); },{"../src/traces/volume":702}],11:[function(_dereq_,module,exports){ 'use strict' module.exports = createViewController var createTurntable = _dereq_('turntable-camera-controller') var createOrbit = _dereq_('orbit-camera-controller') var createMatrix = _dereq_('matrix-camera-controller') function ViewController(controllers, mode) { this._controllerNames = Object.keys(controllers) this._controllerList = this._controllerNames.map(function(n) { return controllers[n] }) this._mode = mode this._active = controllers[mode] if(!this._active) { this._mode = 'turntable' this._active = controllers.turntable } this.modes = this._controllerNames this.computedMatrix = this._active.computedMatrix this.computedEye = this._active.computedEye this.computedUp = this._active.computedUp this.computedCenter = this._active.computedCenter this.computedRadius = this._active.computedRadius } var proto = ViewController.prototype var COMMON_METHODS = [ ['flush', 1], ['idle', 1], ['lookAt', 4], ['rotate', 4], ['pan', 4], ['translate', 4], ['setMatrix', 2], ['setDistanceLimits', 2], ['setDistance', 2] ] COMMON_METHODS.forEach(function(method) { var name = method[0] var argNames = [] for(var i=0; i<method[1]; ++i) { argNames.push('a'+i) } var code = 'var cc=this._controllerList;for(var i=0;i<cc.length;++i){cc[i].'+method[0]+'('+argNames.join()+')}' proto[name] = Function.apply(null, argNames.concat(code)) }) proto.recalcMatrix = function(t) { this._active.recalcMatrix(t) } proto.getDistance = function(t) { return this._active.getDistance(t) } proto.getDistanceLimits = function(out) { return this._active.getDistanceLimits(out) } proto.lastT = function() { return this._active.lastT() } proto.setMode = function(mode) { if(mode === this._mode) { return } var idx = this._controllerNames.indexOf(mode) if(idx < 0) { return } var prev = this._active var next = this._controllerList[idx] var lastT = Math.max(prev.lastT(), next.lastT()) prev.recalcMatrix(lastT) next.setMatrix(lastT, prev.computedMatrix) this._active = next this._mode = mode //Update matrix properties this.computedMatrix = this._active.computedMatrix this.computedEye = this._active.computedEye this.computedUp = this._active.computedUp this.computedCenter = this._active.computedCenter this.computedRadius = this._active.computedRadius } proto.getMode = function() { return this._mode } function createViewController(options) { options = options || {} var eye = options.eye || [0,0,1] var center = options.center || [0,0,0] var up = options.up || [0,1,0] var limits = options.distanceLimits || [0, Infinity] var mode = options.mode || 'turntable' var turntable = createTurntable() var orbit = createOrbit() var matrix = createMatrix() turntable.setDistanceLimits(limits[0], limits[1]) turntable.lookAt(0, eye, center, up) orbit.setDistanceLimits(limits[0], limits[1]) orbit.lookAt(0, eye, center, up) matrix.setDistanceLimits(limits[0], limits[1]) matrix.lookAt(0, eye, center, up) return new ViewController({ turntable: turntable, orbit: orbit, matrix: matrix }, mode) } },{"matrix-camera-controller":286,"orbit-camera-controller":305,"turntable-camera-controller":363}],12:[function(_dereq_,module,exports){ 'use strict' var weakMap = typeof WeakMap === 'undefined' ? _dereq_('weak-map') : WeakMap var createBuffer = _dereq_('gl-buffer') var createVAO = _dereq_('gl-vao') var TriangleCache = new weakMap() function createABigTriangle(gl) { var triangleVAO = TriangleCache.get(gl) var handle = triangleVAO && (triangleVAO._triangleBuffer.handle || triangleVAO._triangleBuffer.buffer) if(!handle || !gl.isBuffer(handle)) { var buf = createBuffer(gl, new Float32Array([-1, -1, -1, 4, 4, -1])) triangleVAO = createVAO(gl, [ { buffer: buf, type: gl.FLOAT, size: 2 } ]) triangleVAO._triangleBuffer = buf TriangleCache.set(gl, triangleVAO) } triangleVAO.bind() gl.drawArrays(gl.TRIANGLES, 0, 3) triangleVAO.unbind() } module.exports = createABigTriangle },{"gl-buffer":106,"gl-vao":186,"weak-map":371}],13:[function(_dereq_,module,exports){ var padLeft = _dereq_('pad-left') module.exports = addLineNumbers function addLineNumbers (string, start, delim) { start = typeof start === 'number' ? start : 1 delim = delim || ': ' var lines = string.split(/\r?\n/) var totalDigits = String(lines.length + start - 1).length return lines.map(function (line, i) { var c = i + start var digits = String(c).length var prefix = padLeft(c, totalDigits - digits) return prefix + delim + line }).join('\n') } },{"pad-left":306}],14:[function(_dereq_,module,exports){ 'use strict' module.exports = affineHull var orient = _dereq_('robust-orientation') function linearlyIndependent(points, d) { var nhull = new Array(d+1) for(var i=0; i<points.length; ++i) { nhull[i] = points[i] } for(var i=0; i<=points.length; ++i) { for(var j=points.length; j<=d; ++j) { var x = new Array(d) for(var k=0; k<d; ++k) { x[k] = Math.pow(j+1-i, k) } nhull[j] = x } var o = orient.apply(void 0, nhull) if(o) { return true } } return false } function affineHull(points) { var n = points.length if(n === 0) { return [] } if(n === 1) { return [0] } var d = points[0].length var frame = [ points[0] ] var index = [ 0 ] for(var i=1; i<n; ++i) { frame.push(points[i]) if(!linearlyIndependent(frame, d)) { frame.pop() continue } index.push(i) if(index.length === d+1) { return index } } return index } },{"robust-orientation":339}],15:[function(_dereq_,module,exports){ 'use strict' module.exports = alphaComplex var delaunay = _dereq_('delaunay-triangulate') var circumradius = _dereq_('circumradius') function alphaComplex(alpha, points) { return delaunay(points).filter(function(cell) { var simplex = new Array(cell.length) for(var i=0; i<cell.length; ++i) { simplex[i] = points[cell[i]] } return circumradius(simplex) * alpha < 1 }) } },{"circumradius":57,"delaunay-triangulate":84}],16:[function(_dereq_,module,exports){ module.exports = alphaShape var ac = _dereq_('alpha-complex') var bnd = _dereq_('simplicial-complex-boundary') function alphaShape(alpha, points) { return bnd(ac(alpha, points)) } },{"alpha-complex":15,"simplicial-complex-boundary":346}],17:[function(_dereq_,module,exports){ module.exports = function _atob(str) { return atob(str) } },{}],18:[function(_dereq_,module,exports){ 'use strict' module.exports = barycentric var solve = _dereq_('robust-linear-solve') function reduce(x) { var r = 0 for(var i=0; i<x.length; ++i) { r += x[i] } return r } function barycentric(simplex, point) { var d = point.length var A = new Array(d+1) for(var i=0; i<d; ++i) { var row = new Array(d+1) for(var j=0; j<=d; ++j) { row[j] = simplex[j][i] } A[i] = row } A[d] = new Array(d+1) for(var i=0; i<=d; ++i) { A[d][i] = 1 } var b = new Array(d+1) for(var i=0; i<d; ++i) { b[i] = point[i] } b[d] = 1.0 var x = solve(A, b) var w = reduce(x[d+1]) if(w === 0) { w = 1.0 } var y = new Array(d+1) for(var i=0; i<=d; ++i) { y[i] = reduce(x[i]) / w } return y } },{"robust-linear-solve":338}],19:[function(_dereq_,module,exports){ 'use strict' exports.byteLength = byteLength exports.toByteArray = toByteArray exports.fromByteArray = fromByteArray var lookup = [] var revLookup = [] var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' for (var i = 0, len = code.length; i < len; ++i) { lookup[i] = code[i] revLookup[code.charCodeAt(i)] = i } // Support decoding URL-safe base64 strings, as Node.js does. // See: https://en.wikipedia.org/wiki/Base64#URL_applications revLookup['-'.charCodeAt(0)] = 62 revLookup['_'.charCodeAt(0)] = 63 function getLens (b64) { var len = b64.length if (len % 4 > 0) { throw new Error('Invalid string. Length must be a multiple of 4') } // Trim off extra bytes after placeholder bytes are found // See: https://github.com/beatgammit/base64-js/issues/42 var validLen = b64.indexOf('=') if (validLen === -1) validLen = len var placeHoldersLen = validLen === len ? 0 : 4 - (validLen % 4) return [validLen, placeHoldersLen] } // base64 is 4/3 + up to two characters of the original data function byteLength (b64) { var lens = getLens(b64) var validLen = lens[0] var placeHoldersLen = lens[1] return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen } function _byteLength (b64, validLen, placeHoldersLen) { return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen } function toByteArray (b64) { var tmp var lens = getLens(b64) var validLen = lens[0] var placeHoldersLen = lens[1] var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen)) var curByte = 0 // if there are placeholders, only get up to the last complete 4 chars var len = placeHoldersLen > 0 ? validLen - 4 : validLen var i for (i = 0; i < len; i += 4) { tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)] arr[curByte++] = (tmp >> 16) & 0xFF arr[curByte++] = (tmp >> 8) & 0xFF arr[curByte++] = tmp & 0xFF } if (placeHoldersLen === 2) { tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4) arr[curByte++] = tmp & 0xFF } if (placeHoldersLen === 1) { tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2) arr[curByte++] = (tmp >> 8) & 0xFF arr[curByte++] = tmp & 0xFF } return arr } function tripletToBase64 (num) { return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F] } function encodeChunk (uint8, start, end) { var tmp var output = [] for (var i = start; i < end; i += 3) { tmp = ((uint8[i] << 16) & 0xFF0000) + ((uint8[i + 1] << 8) & 0xFF00) + (uint8[i + 2] & 0xFF) output.push(tripletToBase64(tmp)) } return output.join('') } function fromByteArray (uint8) { var tmp var len = uint8.length var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes var parts = [] var maxChunkLength = 16383 // must be multiple of 3 // go through the array every three bytes, we'll deal with trailing stuff later for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { parts.push(encodeChunk( uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength) )) } // pad the end with zeros, but make sure to not forget the extra bytes if (extraBytes === 1) { tmp = uint8[len - 1] parts.push( lookup[tmp >> 2] + lookup[(tmp << 4) & 0x3F] + '==' ) } else if (extraBytes === 2) { tmp = (uint8[len - 2] << 8) + uint8[len - 1] parts.push( lookup[tmp >> 10] + lookup[(tmp >> 4) & 0x3F] + lookup[(tmp << 2) & 0x3F] + '=' ) } return parts.join('') } },{}],20:[function(_dereq_,module,exports){ 'use strict' var rationalize = _dereq_('./lib/rationalize') module.exports = add function add(a, b) { return rationalize( a[0].mul(b[1]).add(b[0].mul(a[1])), a[1].mul(b[1])) } },{"./lib/rationalize":30}],21:[function(_dereq_,module,exports){ 'use strict' module.exports = cmp function cmp(a, b) { return a[0].mul(b[1]).cmp(b[0].mul(a[1])) } },{}],22:[function(_dereq_,module,exports){ 'use strict' var rationalize = _dereq_('./lib/rationalize') module.exports = div function div(a, b) { return rationalize(a[0].mul(b[1]), a[1].mul(b[0])) } },{"./lib/rationalize":30}],23:[function(_dereq_,module,exports){ 'use strict' var isRat = _dereq_('./is-rat') var isBN = _dereq_('./lib/is-bn') var num2bn = _dereq_('./lib/num-to-bn') var str2bn = _dereq_('./lib/str-to-bn') var rationalize = _dereq_('./lib/rationalize') var div = _dereq_('./div') module.exports = makeRational function makeRational(numer, denom) { if(isRat(numer)) { if(denom) { return div(numer, makeRational(denom)) } return [numer[0].clone(), numer[1].clone()] } var shift = 0 var a, b if(isBN(numer)) { a = numer.clone() } else if(typeof numer === 'string') { a = str2bn(numer) } else if(numer === 0) { return [num2bn(0), num2bn(1)] } else if(numer === Math.floor(numer)) { a = num2bn(numer) } else { while(numer !== Math.floor(numer)) { numer = numer * Math.pow(2, 256) shift -= 256 } a = num2bn(numer) } if(isRat(denom)) { a.mul(denom[1]) b = denom[0].clone() } else if(isBN(denom)) { b = denom.clone() } else if(typeof denom === 'string') { b = str2bn(denom) } else if(!denom) { b = num2bn(1) } else if(denom === Math.floor(denom)) { b = num2bn(denom) } else { while(denom !== Math.floor(denom)) { denom = denom * Math.pow(2, 256) shift += 256 } b = num2bn(denom) } if(shift > 0) { a = a.ushln(shift) } else if(shift < 0) { b = b.ushln(-shift) } return rationalize(a, b) } },{"./div":22,"./is-rat":24,"./lib/is-bn":28,"./lib/num-to-bn":29,"./lib/rationalize":30,"./lib/str-to-bn":31}],24:[function(_dereq_,module,exports){ 'use strict' var isBN = _dereq_('./lib/is-bn') module.exports = isRat function isRat(x) { return Array.isArray(x) && x.length === 2 && isBN(x[0]) && isBN(x[1]) } },{"./lib/is-bn":28}],25:[function(_dereq_,module,exports){ 'use strict' var BN = _dereq_('bn.js') module.exports = sign function sign (x) { return x.cmp(new BN(0)) } },{"bn.js":38}],26:[function(_dereq_,module,exports){ 'use strict' var sign = _dereq_('./bn-sign') module.exports = bn2num //TODO: Make this better function bn2num(b) { var l = b.length var words = b.words var out = 0 if (l === 1) { out = words[0] } else if (l === 2) { out = words[0] + (words[1] * 0x4000000) } else { for (var i = 0; i < l; i++) { var w = words[i] out += w * Math.pow(0x4000000, i) } } return sign(b) * out } },{"./bn-sign":25}],27:[function(_dereq_,module,exports){ 'use strict' var db = _dereq_('double-bits') var ctz = _dereq_('bit-twiddle').countTrailingZeros module.exports = ctzNumber //Counts the number of trailing zeros function ctzNumber(x) { var l = ctz(db.lo(x)) if(l < 32) { return l } var h = ctz(db.hi(x)) if(h > 20) { return 52 } return h + 32 } },{"bit-twiddle":37,"double-bits":85}],28:[function(_dereq_,module,exports){ 'use strict' var BN = _dereq_('bn.js') module.exports = isBN //Test if x is a bignumber //FIXME: obviously this is the wrong way to do it function isBN(x) { return x && typeof x === 'object' && Boolean(x.words) } },{"bn.js":38}],29:[function(_dereq_,module,exports){ 'use strict' var BN = _dereq_('bn.js') var db = _dereq_('double-bits') module.exports = num2bn function num2bn(x) { var e = db.exponent(x) if(e < 52) { return new BN(x) } else { return (new BN(x * Math.pow(2, 52-e))).ushln(e-52) } } },{"bn.js":38,"double-bits":85}],30:[function(_dereq_,module,exports){ 'use strict' var num2bn = _dereq_('./num-to-bn') var sign = _dereq_('./bn-sign') module.exports = rationalize function rationalize(numer, denom) { var snumer = sign(numer) var sdenom = sign(denom) if(snumer === 0) { return [num2bn(0), num2bn(1)] } if(sdenom === 0) { return [num2bn(0), num2bn(0)] } if(sdenom < 0) { numer = numer.neg() denom = denom.neg() } var d = numer.gcd(denom) if(d.cmpn(1)) { return [ numer.div(d), denom.div(d) ] } return [ numer, denom ] } },{"./bn-sign":25,"./num-to-bn":29}],31:[function(_dereq_,module,exports){ 'use strict' var BN = _dereq_('bn.js') module.exports = str2BN function str2BN(x) { return new BN(x) } },{"bn.js":38}],32:[function(_dereq_,module,exports){ 'use strict' var rationalize = _dereq_('./lib/rationalize') module.exports = mul function mul(a, b) { return rationalize(a[0].mul(b[0]), a[1].mul(b[1])) } },{"./lib/rationalize":30}],33:[function(_dereq_,module,exports){ 'use strict' var bnsign = _dereq_('./lib/bn-sign') module.exports = sign function sign(x) { return bnsign(x[0]) * bnsign(x[1]) } },{"./lib/bn-sign":25}],34:[function(_dereq_,module,exports){ 'use strict' var rationalize = _dereq_('./lib/rationalize') module.exports = sub function sub(a, b) { return rationalize(a[0].mul(b[1]).sub(a[1].mul(b[0])), a[1].mul(b[1])) } },{"./lib/rationalize":30}],35:[function(_dereq_,module,exports){ 'use strict' var bn2num = _dereq_('./lib/bn-to-num') var ctz = _dereq_('./lib/ctz') module.exports = roundRat // Round a rational to the closest float function roundRat (f) { var a = f[0] var b = f[1] if (a.cmpn(0) === 0) { return 0 } var h = a.abs().divmod(b.abs()) var iv = h.div var x = bn2num(iv) var ir = h.mod var sgn = (a.negative !== b.negative) ? -1 : 1 if (ir.cmpn(0) === 0) { return sgn * x } if (x) { var s = ctz(x) + 4 var y = bn2num(ir.ushln(s).divRound(b)) return sgn * (x + y * Math.pow(2, -s)) } else { var ybits = b.bitLength() - ir.bitLength() + 53 var y = bn2num(ir.ushln(ybits).divRound(b)) if (ybits < 1023) { return sgn * y * Math.pow(2, -ybits) } y *= Math.pow(2, -1023) return sgn * y * Math.pow(2, 1023 - ybits) } } },{"./lib/bn-to-num":26,"./lib/ctz":27}],36:[function(_dereq_,module,exports){ "use strict" function compileSearch(funcName, predicate, reversed, extraArgs, earlyOut) { var code = [ "function ", funcName, "(a,l,h,", extraArgs.join(","), "){", earlyOut ? "" : "var i=", (reversed ? "l-1" : "h+1"), ";while(l<=h){var m=(l+h)>>>1,x=a[m]"] if(earlyOut) { if(predicate.indexOf("c") < 0) { code.push(";if(x===y){return m}else if(x<=y){") } else { code.push(";var p=c(x,y);if(p===0){return m}else if(p<=0){") } } else { code.push(";if(", predicate, "){i=m;") } if(reversed) { code.push("l=m+1}else{h=m-1}") } else { code.push("h=m-1}else{l=m+1}") } code.push("}") if(earlyOut) { code.push("return -1};") } else { code.push("return i};") } return code.join("") } function compileBoundsSearch(predicate, reversed, suffix, earlyOut) { var result = new Function([ compileSearch("A", "x" + predicate + "y", reversed, ["y"], earlyOut), compileSearch("P", "c(x,y)" + predicate + "0", reversed, ["y", "c"], earlyOut), "function dispatchBsearch", suffix, "(a,y,c,l,h){\ if(typeof(c)==='function'){\ return P(a,(l===void 0)?0:l|0,(h===void 0)?a.length-1:h|0,y,c)\ }else{\ return A(a,(c===void 0)?0:c|0,(l===void 0)?a.length-1:l|0,y)\ }}\ return dispatchBsearch", suffix].join("")) return result() } module.exports = { ge: compileBoundsSearch(">=", false, "GE"), gt: compileBoundsSearch(">", false, "GT"), lt: compileBoundsSearch("<", true, "LT"), le: compileBoundsSearch("<=", true, "LE"), eq: compileBoundsSearch("-", true, "EQ", true) } },{}],37:[function(_dereq_,module,exports){ /** * Bit twiddling hacks for JavaScript. * * Author: Mikola Lysenko * * Ported from Stanford bit twiddling hack library: * http://graphics.stanford.edu/~seander/bithacks.html */ "use strict"; "use restrict"; //Number of bits in an integer var INT_BITS = 32; //Constants exports.INT_BITS = INT_BITS; exports.INT_MAX = 0x7fffffff; exports.INT_MIN = -1<<(INT_BITS-1); //Returns -1, 0, +1 depending on sign of x exports.sign = function(v) { return (v > 0) - (v < 0); } //Computes absolute value of integer exports.abs = function(v) { var mask = v >> (INT_BITS-1); return (v ^ mask) - mask; } //Computes minimum of integers x and y exports.min = function(x, y) { return y ^ ((x ^ y) & -(x < y)); } //Computes maximum of integers x and y exports.max = function(x, y) { return x ^ ((x ^ y) & -(x < y)); } //Checks if a number is a power of two exports.isPow2 = function(v) { return !(v & (v-1)) && (!!v); } //Computes log base 2 of v exports.log2 = function(v) { var r, shift; r = (v > 0xFFFF) << 4; v >>>= r; shift = (v > 0xFF ) << 3; v >>>= shift; r |= shift; shift = (v > 0xF ) << 2; v >>>= shift; r |= shift; shift = (v > 0x3 ) << 1; v >>>= shift; r |= shift; return r | (v >> 1); } //Computes log base 10 of v exports.log10 = function(v) { return (v >= 1000000000) ? 9 : (v >= 100000000) ? 8 : (v >= 10000000) ? 7 : (v >= 1000000) ? 6 : (v >= 100000) ? 5 : (v >= 10000) ? 4 : (v >= 1000) ? 3 : (v >= 100) ? 2 : (v >= 10) ? 1 : 0; } //Counts number of bits exports.popCount = function(v) { v = v - ((v >>> 1) & 0x55555555); v = (v & 0x33333333) + ((v >>> 2) & 0x33333333); return ((v + (v >>> 4) & 0xF0F0F0F) * 0x1010101) >>> 24; } //Counts number of trailing zeros function countTrailingZeros(v) { var c = 32; v &= -v; if (v) c--; if (v & 0x0000FFFF) c -= 16; if (v & 0x00FF00FF) c -= 8; if (v & 0x0F0F0F0F) c -= 4; if (v & 0x33333333) c -= 2; if (v & 0x55555555) c -= 1; return c; } exports.countTrailingZeros = countTrailingZeros; //Rounds to next power of 2 exports.nextPow2 = function(v) { v += v === 0; --v; v |= v >>> 1; v |= v >>> 2; v |= v >>> 4; v |= v >>> 8; v |= v >>> 16; return v + 1; } //Rounds down to previous power of 2 exports.prevPow2 = function(v) { v |= v >>> 1; v |= v >>> 2; v |= v >>> 4; v |= v >>> 8; v |= v >>> 16; return v - (v>>>1); } //Computes parity of word exports.parity = function(v) { v ^= v >>> 16; v ^= v >>> 8; v ^= v >>> 4; v &= 0xf; return (0x6996 >>> v) & 1; } var REVERSE_TABLE = new Array(256); (function(tab) { for(var i=0; i<256; ++i) { var v = i, r = i, s = 7; for (v >>>= 1; v; v >>>= 1) { r <<= 1; r |= v & 1; --s; } tab[i] = (r << s) & 0xff; } })(REVERSE_TABLE); //Reverse bits in a 32 bit word exports.reverse = function(v) { return (REVERSE_TABLE[ v & 0xff] << 24) | (REVERSE_TABLE[(v >>> 8) & 0xff] << 16) | (REVERSE_TABLE[(v >>> 16) & 0xff] << 8) | REVERSE_TABLE[(v >>> 24) & 0xff]; } //Interleave bits of 2 coordinates with 16 bits. Useful for fast quadtree codes exports.interleave2 = function(x, y) { x &= 0xFFFF; x = (x | (x << 8)) & 0x00FF00FF; x = (x | (x << 4)) & 0x0F0F0F0F; x = (x | (x << 2)) & 0x33333333; x = (x | (x << 1)) & 0x55555555; y &= 0xFFFF; y = (y | (y << 8)) & 0x00FF00FF; y = (y | (y << 4)) & 0x0F0F0F0F; y = (y | (y << 2)) & 0x33333333; y = (y | (y << 1)) & 0x55555555; return x | (y << 1); } //Extracts the nth interleaved component exports.deinterleave2 = function(v, n) { v = (v >>> n) & 0x55555555; v = (v | (v >>> 1)) & 0x33333333; v = (v | (v >>> 2)) & 0x0F0F0F0F; v = (v | (v >>> 4)) & 0x00FF00FF; v = (v | (v >>> 16)) & 0x000FFFF; return (v << 16) >> 16; } //Interleave bits of 3 coordinates, each with 10 bits. Useful for fast octree codes exports.interleave3 = function(x, y, z) { x &= 0x3FF; x = (x | (x<<16)) & 4278190335; x = (x | (x<<8)) & 251719695; x = (x | (x<<4)) & 3272356035; x = (x | (x<<2)) & 1227133513; y &= 0x3FF; y = (y | (y<<16)) & 4278190335; y = (y | (y<<8)) & 251719695; y = (y | (y<<4)) & 3272356035; y = (y | (y<<2)) & 1227133513; x |= (y << 1); z &= 0x3FF; z = (z | (z<<16)) & 4278190335; z = (z | (z<<8)) & 251719695; z = (z | (z<<4)) & 3272356035; z = (z | (z<<2)) & 1227133513; return x | (z << 2); } //Extracts nth interleaved component of a 3-tuple exports.deinterleave3 = function(v, n) { v = (v >>> n) & 1227133513; v = (v | (v>>>2)) & 3272356035; v = (v | (v>>>4)) & 251719695; v = (v | (v>>>8)) & 4278190335; v = (v | (v>>>16)) & 0x3FF; return (v<<22)>>22; } //Computes next combination in colexicographic order (this is mistakenly called nextPermutation on the bit twiddling hacks page) exports.nextCombination = function(v) { var t = v | (v - 1); return (t + 1) | (((~t & -~t) - 1) >>> (countTrailingZeros(v) + 1)); } },{}],38:[function(_dereq_,module,exports){ (function (module, exports) { 'use strict'; // Utils function assert (val, msg) { if (!val) throw new Error(msg || 'Assertion failed'); } // Could use `inherits` module, but don't want to move from single file // architecture yet. function inherits (ctor, superCtor) { ctor.super_ = superCtor; var TempCtor = function () {}; TempCtor.prototype = superCtor.prototype; ctor.prototype = new TempCtor(); ctor.prototype.constructor = ctor; } // BN function BN (number, base, endian) { if (BN.isBN(number)) { return number; } this.negative = 0; this.words = null; this.length = 0; // Reduction context this.red = null; if (number !== null) { if (base === 'le' || base === 'be') { endian = base; base = 10; } this._init(number || 0, base || 10, endian || 'be'); } } if (typeof module === 'object') { module.exports = BN; } else { exports.BN = BN; } BN.BN = BN; BN.wordSize = 26; var Buffer; try { Buffer = _dereq_('buffer').Buffer; } catch (e) { } BN.isBN = function isBN (num) { if (num instanceof BN) { return true; } return num !== null && typeof num === 'object' && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words); }; BN.max = function max (left, right) { if (left.cmp(right) > 0) return left; return right; }; BN.min = function min (left, right) { if (left.cmp(right) < 0) return left; return right; }; BN.prototype._init = function init (number, base, endian) { if (typeof number === 'number') { return this._initNumber(number, base, endian); } if (typeof number === 'object') { return this._initArray(number, base, endian); } if (base === 'hex') { base = 16; } assert(base === (base | 0) && base >= 2 && base <= 36); number = number.toString().replace(/\s+/g, ''); var start = 0; if (number[0] === '-') { start++; } if (base === 16) { this._parseHex(number, start); } else { this._parseBase(number, base, start); } if (number[0] === '-') { this.negative = 1; } this.strip(); if (endian !== 'le') return; this._initArray(this.toArray(), base, endian); }; BN.prototype._initNumber = function _initNumber (number, base, endian) { if (number < 0) { this.negative = 1; number = -number; } if (number < 0x4000000) { this.words = [ number & 0x3ffffff ]; this.length = 1; } else if (number < 0x10000000000000) { this.words = [ number & 0x3ffffff, (number / 0x4000000) & 0x3ffffff ]; this.length = 2; } else { assert(number < 0x20000000000000); // 2 ^ 53 (unsafe) this.words = [ number & 0x3ffffff, (number / 0x4000000) & 0x3ffffff, 1 ]; this.length = 3; } if (endian !== 'le') return; // Reverse the bytes this._initArray(this.toArray(), base, endian); }; BN.prototype._initArray = function _initArray (number, base, endian) { // Perhaps a Uint8Array assert(typeof number.length === 'number'); if (number.length <= 0) { this.words = [ 0 ]; this.length = 1; return this; } this.length = Math.ceil(number.length / 3); this.words = new Array(this.length); for (var i = 0; i < this.length; i++) { this.words[i] = 0; } var j, w; var off = 0; if (endian === 'be') { for (i = number.length - 1, j = 0; i >= 0; i -= 3) { w = number[i] | (number[i - 1] << 8) | (number[i - 2] << 16); this.words[j] |= (w << off) & 0x3ffffff; this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff; off += 24; if (off >= 26) { off -= 26; j++; } } } else if (endian === 'le') { for (i = 0, j = 0; i < number.length; i += 3) { w = number[i] | (number[i + 1] << 8) | (number[i + 2] << 16); this.words[j] |= (w << off) & 0x3ffffff; this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff; off += 24; if (off >= 26) { off -= 26; j++; } } } return this.strip(); }; function parseHex (str, start, end) { var r = 0; var len = Math.min(str.length, end); for (var i = start; i < len; i++) { var c = str.charCodeAt(i) - 48; r <<= 4; // 'a' - 'f' if (c >= 49 && c <= 54) { r |= c - 49 + 0xa; // 'A' - 'F' } else if (c >= 17 && c <= 22) { r |= c - 17 + 0xa; // '0' - '9' } else { r |= c & 0xf; } } return r; } BN.prototype._parseHex = function _parseHex (number, start) { // Create possibly bigger array to ensure that it fits the number this.length = Math.ceil((number.length - start) / 6); this.words = new Array(this.length); for (var i = 0; i < this.length; i++) { this.words[i] = 0; } var j, w; // Scan 24-bit chunks and add them to the number var off = 0; for (i = number.length - 6, j = 0; i >= start; i -= 6) { w = parseHex(number, i, i + 6); this.words[j] |= (w << off) & 0x3ffffff; // NOTE: `0x3fffff` is intentional here, 26bits max shift + 24bit hex limb this.words[j + 1] |= w >>> (26 - off) & 0x3fffff; off += 24; if (off >= 26) { off -= 26; j++; } } if (i + 6 !== start) { w = parseHex(number, start, i + 6); this.words[j] |= (w << off) & 0x3ffffff; this.words[j + 1] |= w >>> (26 - off) & 0x3fffff; } this.strip(); }; function parseBase (str, start, end, mul) { var r = 0; var len = Math.min(str.length, end); for (var i = start; i < len; i++) { var c = str.charCodeAt(i) - 48; r *= mul; // 'a' if (c >= 49) { r += c - 49 + 0xa; // 'A' } else if (c >= 17) { r += c - 17 + 0xa; // '0' - '9' } else { r += c; } } return r; } BN.prototype._parseBase = function _parseBase (number, base, start) { // Initialize as zero this.words = [ 0 ]; this.length = 1; // Find length of limb in base for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) { limbLen++; } limbLen--; limbPow = (limbPow / base) | 0; var total = number.length - start; var mod = total % limbLen; var end = Math.min(total, total - mod) + start; var word = 0; for (var i = start; i < end; i += limbLen) { word = parseBase(number, i, i + limbLen, base); this.imuln(limbPow); if (this.words[0] + word < 0x4000000) { this.words[0] += word; } else { this._iaddn(word); } } if (mod !== 0) { var pow = 1; word = parseBase(number, i, number.length, base); for (i = 0; i < mod; i++) { pow *= base; } this.imuln(pow); if (this.words[0] + word < 0x4000000) { this.words[0] += word; } else { this._iaddn(word); } } }; BN.prototype.copy = function copy (dest) { dest.words = new Array(this.length); for (var i = 0; i < this.length; i++) { dest.words[i] = this.words[i]; } dest.length = this.length; dest.negative = this.negative; dest.red = this.red; }; BN.prototype.clone = function clone () { var r = new BN(null); this.copy(r); return r; }; BN.prototype._expand = function _expand (size) { while (this.length < size) { this.words[this.length++] = 0; } return this; }; // Remove leading `0` from `this` BN.prototype.strip = function strip () { while (this.length > 1 && this.words[this.length - 1] === 0) { this.length--; } return this._normSign(); }; BN.prototype._normSign = function _normSign () { // -0 = 0 if (this.length === 1 && this.words[0] === 0) { this.negative = 0; } return this; }; BN.prototype.inspect = function inspect () { return (this.red ? '<BN-R: ' : '<BN: ') + this.toString(16) + '>'; }; /* var zeros = []; var groupSizes = []; var groupBases = []; var s = ''; var i = -1; while (++i < BN.wordSize) { zeros[i] = s; s += '0'; } groupSizes[0] = 0; groupSizes[1] = 0; groupBases[0] = 0; groupBases[1] = 0; var base = 2 - 1; while (++base < 36 + 1) { var groupSize = 0; var groupBase = 1; while (groupBase < (1 << BN.wordSize) / base) { groupBase *= base; groupSize += 1; } groupSizes[base] = groupSize; groupBases[base] = groupBase; } */ var zeros = [ '', '0', '00', '000', '0000', '00000', '000000', '0000000', '00000000', '000000000', '0000000000', '00000000000', '000000000000', '0000000000000', '00000000000000', '000000000000000', '0000000000000000', '00000000000000000', '000000000000000000', '0000000000000000000', '00000000000000000000', '000000000000000000000', '0000000000000000000000', '00000000000000000000000', '000000000000000000000000', '0000000000000000000000000' ]; var groupSizes = [ 0, 0, 25, 16, 12, 11, 10, 9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 ]; var groupBases = [ 0, 0, 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216, 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625, 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632, 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149, 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176 ]; BN.prototype.toString = function toString (base, padding) { base = base || 10; padding = padding | 0 || 1; var out; if (base === 16 || base === 'hex') { out = ''; var off = 0; var carry = 0; for (var i = 0; i < this.length; i++) { var w = this.words[i]; var word = (((w << off) | carry) & 0xffffff).toString(16); carry = (w >>> (24 - off)) & 0xffffff; if (carry !== 0 || i !== this.length - 1) { out = zeros[6 - word.length] + word + out; } else { out = word + out; } off += 2; if (off >= 26) { off -= 26; i--; } } if (carry !== 0) { out = carry.toString(16) + out; } while (out.length % padding !== 0) { out = '0' + out; } if (this.negative !== 0) { out = '-' + out; } return out; } if (base === (base | 0) && base >= 2 && base <= 36) { // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base)); var groupSize = groupSizes[base]; // var groupBase = Math.pow(base, groupSize); var groupBase = groupBases[base]; out = ''; var c = this.clone(); c.negative = 0; while (!c.isZero()) { var r = c.modn(groupBase).toString(base); c = c.idivn(groupBase); if (!c.isZero()) { out = zeros[groupSize - r.length] + r + out; } else { out = r + out; } } if (this.isZero()) { out = '0' + out; } while (out.length % padding !== 0) { out = '0' + out; } if (this.negative !== 0) { out = '-' + out; } return out; } assert(false, 'Base should be between 2 and 36'); }; BN.prototype.toNumber = function toNumber () { var ret = this.words[0]; if (this.length === 2) { ret += this.words[1] * 0x4000000; } else if (this.length === 3 && this.words[2] === 0x01) { // NOTE: at this stage it is known that the top bit is set ret += 0x10000000000000 + (this.words[1] * 0x4000000); } else if (this.length > 2) { assert(false, 'Number can only safely store up to 53 bits'); } return (this.negative !== 0) ? -ret : ret; }; BN.prototype.toJSON = function toJSON () { return this.toString(16); }; BN.prototype.toBuffer = function toBuffer (endian, length) { assert(typeof Buffer !== 'undefined'); return this.toArrayLike(Buffer, endian, length); }; BN.prototype.toArray = function toArray (endian, length) { return this.toArrayLike(Array, endian, length); }; BN.prototype.toArrayLike = function toArrayLike (ArrayType, endian, length) { var byteLength = this.byteLength(); var reqLength = length || Math.max(1, byteLength); assert(byteLength <= reqLength, 'byte array longer than desired length'); assert(reqLength > 0, 'Requested array length <= 0'); this.strip(); var littleEndian = endian === 'le'; var res = new ArrayType(reqLength); var b, i; var q = this.clone(); if (!littleEndian) { // Assume big-endian for (i = 0; i < reqLength - byteLength; i++) { res[i] = 0; } for (i = 0; !q.isZero(); i++) { b = q.andln(0xff); q.iushrn(8); res[reqLength - i - 1] = b; } } else { for (i = 0; !q.isZero(); i++) { b = q.andln(0xff); q.iushrn(8); res[i] = b; } for (; i < reqLength; i++) { res[i] = 0; } } return res; }; if (Math.clz32) { BN.prototype._countBits = function _countBits (w) { return 32 - Math.clz32(w); }; } else { BN.prototype._countBits = function _countBits (w) { var t = w; var r = 0; if (t >= 0x1000) { r += 13; t >>>= 13; } if (t >= 0x40) { r += 7; t >>>= 7; } if (t >= 0x8) { r += 4; t >>>= 4; } if (t >= 0x02) { r += 2; t >>>= 2; } return r + t; }; } BN.prototype._zeroBits = function _zeroBits (w) { // Short-cut if (w === 0) return 26; var t = w; var r = 0; if ((t & 0x1fff) === 0) { r += 13; t >>>= 13; } if ((t & 0x7f) === 0) { r += 7; t >>>= 7; } if ((t & 0xf) === 0) { r += 4; t >>>= 4; } if ((t & 0x3) === 0) { r += 2; t >>>= 2; } if ((t & 0x1) === 0) { r++; } return r; }; // Return number of used bits in a BN BN.prototype.bitLength = function bitLength () { var w = this.words[this.length - 1]; var hi = this._countBits(w); return (this.length - 1) * 26 + hi; }; function toBitArray (num) { var w = new Array(num.bitLength()); for (var bit = 0; bit < w.length; bit++) { var off = (bit / 26) | 0; var wbit = bit % 26; w[bit] = (num.words[off] & (1 << wbit)) >>> wbit; } return w; } // Number of trailing zero bits BN.prototype.zeroBits = function zeroBits () { if (this.isZero()) return 0; var r = 0; for (var i = 0; i < this.length; i++) { var b = this._zeroBits(this.words[i]); r += b; if (b !== 26) break; } return r; }; BN.prototype.byteLength = function byteLength () { return Math.ceil(this.bitLength() / 8); }; BN.prototype.toTwos = function toTwos (width) { if (this.negative !== 0) { return this.abs().inotn(width).iaddn(1); } return this.clone(); }; BN.prototype.fromTwos = function fromTwos (width) { if (this.testn(width - 1)) { return this.notn(width).iaddn(1).ineg(); } return this.clone(); }; BN.prototype.isNeg = function isNeg () { return this.negative !== 0; }; // Return negative clone of `this` BN.prototype.neg = function neg () { return this.clone().ineg(); }; BN.prototype.ineg = function ineg () { if (!this.isZero()) { this.negative ^= 1; } return this; }; // Or `num` with `this` in-place BN.prototype.iuor = function iuor (num) { while (this.length < num.length) { this.words[this.length++] = 0; } for (var i = 0; i < nu