Code Duplication    Length = 1-9 lines in 2 locations

index.js 1 location

@@ 48-56 (lines=9) @@
45
   * @param {number} ebits The exponent bits.
46
   * @param {number} fbits The fraction bits.
47
   */
48
  constructor(ebits, fbits) {
49
    this.ebits = ebits;
50
    this.fbits = fbits;
51
    this.bias = (1 << (ebits - 1)) - 1;
52
    this.numBytes = Math.ceil((ebits + fbits) / 8);
53
    this.biasP2 = Math.pow(2, this.bias + 1);
54
    this.ebitsFbits = (ebits + fbits);
55
    this.fbias = Math.pow(2, -(8 * this.numBytes - 1 - ebits));
56
  }
57
58
  /**
59
   * Pack a IEEE 754 floating point number.

dist/ieee754-buffer.js 1 location

@@ 1-1 (lines=1) @@
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(e,a){this.ebits=e;this.fbits=a;this.bias=(1<<e-1)-1;this.numBytes=Math.ceil((e+a)/8);this.biasP2=Math.pow(2,this.bias+1);this.ebitsFbits=e+a;this.fbias=Math.pow(2,-(8*this.numBytes-1-e))};g.prototype.pack=function(e,a,f){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=this.roundToEven(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=this.roundToEven(b)-Math.pow(2,this.fbits))):(b=this.roundToEven(a/Math.pow(2,1-this.bias-this.fbits)),c=0));return this.packFloatBits_(e,f,d,c,b)};g.prototype.unpack=
3
function(e,a){for(var f=(1<<this.ebits)-1,d="",c=this.numBytes-1;0<=c;c--){var b=e[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==f)return 0!==parseInt(d,2)?NaN:Infinity*c;0===b?(b+=1,f=parseInt(d,2)):f=parseInt("1"+d,2);return c*f*this.fbias*Math.pow(2,b-this.bias)};g.prototype.packFloatBits_=function(e,a,f,d,c){var b=[];b.push(f);for(f=this.ebits;0<f;--f)b[f]=d%2?1:0,d=Math.floor(d/
4
2);d=b.length;for(f=this.fbits;0<f;--f)b[d+f]=c%2?1:0,c=Math.floor(c/2);c=b.join("");b=this.numBytes+a-1;for(d=a;b>=a;)e[b]=parseInt(c.substring(0,8),2),c=c.substring(8),b--,d++;return d};g.prototype.roundToEven=function(e){var a=Math.floor(e);e-=a;return.5>e?a:.5<e?a+1:a%2?a+1:a};h.IEEE754Buffer=g;Object.defineProperty(h,"__esModule",{value:!0})});