1
|
|
|
(function(h,g){"object"===typeof exports&&"undefined"!==typeof module?g(exports):"function"===typeof define&&define.amd?define(["exports"],g):(h=h||self,g(h.IEEE754Buffer={}))})(this,function(h){var g=function(f,a){this.ebits=f;this.fbits=a;this.bias=(1<<f-1)-1;this.numBytes=Math.ceil((f+a)/8);this.biasP2=Math.pow(2,this.bias+1);this.ebitsFbits=f+a;this.fbias=Math.pow(2,-(8*this.numBytes-1-f))};g.prototype.pack=function(f,a,e){Math.abs(a)>this.biasP2-2*this.ebitsFbits&&(a=0>a?-Infinity:Infinity); |
2
|
|
|
var d=0>((a=+a)||1/a)?1:0>a?1:0;a=Math.abs(a);var c=Math.min(Math.floor(Math.log(a)/Math.LN2),1023),b=Math.round(a/Math.pow(2,c)*Math.pow(2,this.fbits));a!==a?(b=Math.pow(2,this.fbits-1),c=(1<<this.ebits)-1):0!==a&&(a>=Math.pow(2,1-this.bias)?(2<=b/Math.pow(2,this.fbits)&&(c+=1,b=1),c>this.bias?(c=(1<<this.ebits)-1,b=0):(c+=this.bias,b=Math.round(b)-Math.pow(2,this.fbits))):(b=Math.round(a/Math.pow(2,1-this.bias-this.fbits)),c=0));return this.packFloatBits_(f,e,d,c,b)};g.prototype.unpack=function(f, |
3
|
|
|
a){for(var e=(1<<this.ebits)-1,d="",c=this.numBytes-1;0<=c;c--){var b=f[c+a].toString(2);d+="00000000".substring(b.length)+b}c="1"==d.charAt(0)?-1:1;d=d.substring(1);b=parseInt(d.substring(0,this.ebits),2);d=d.substring(this.ebits);if(b==e)return 0!==parseInt(d,2)?NaN:Infinity*c;0===b?(b+=1,e=parseInt(d,2)):e=parseInt("1"+d,2);return c*e*this.fbias*Math.pow(2,b-this.bias)};g.prototype.packFloatBits_=function(f,a,e,d,c){var b=[];b.push(e);for(e=this.ebits;0<e;--e)b[e]=d%2?1:0,d=Math.floor(d/2);d=b.length; |
4
|
|
|
for(e=this.fbits;0<e;--e)b[d+e]=c%2?1:0,c=Math.floor(c/2);c=b.join("");b=this.numBytes+a-1;for(d=a;b>=a;)f[b]=parseInt(c.substring(0,8),2),c=c.substring(8),b--,d++;return d};h.IEEE754Buffer=g;Object.defineProperty(h,"__esModule",{value:!0})}); |