AIManage/public/onnx/onnx_view/base.js

1 line
16 KiB
JavaScript
Raw Normal View History

2024-06-06 22:17:58 +08:00
const base={};base.Int64=class Int64{constructor(low,high){this.low=low|0;this.high=high|0}static create(value){if(isNaN(value)){return base.Int64.zero}if(value<=-0x8000000000000000){return base.Int64.min}if(value+1>=0x8000000000000000){return base.Int64.max}if(value<0){return base.Int64.create(-value).negate()}return new base.Int64(value%4294967296|0,value/4294967296)}get isZero(){return this.low===0&&this.high===0}get isNegative(){return this.high<0}negate(){if(this.equals(base.Int64.min)){return base.Int64.min}return this.not().add(base.Int64.one)}not(){return new base.Int64(~this.low,~this.high)}equals(other){if(!(other instanceof base.Int64)&&this.high>>>31===1&&other.high>>>31===1){return false}return this.high===other.high&&this.low===other.low}compare(other){if(this.equals(other)){return 0}const thisNeg=this.isNegative;const otherNeg=other.isNegative;if(thisNeg&&!otherNeg){return-1}if(!thisNeg&&otherNeg){return 1}return this.subtract(other).isNegative?-1:1}add(other){return base.Utility.add(this,other,false)}subtract(other){return base.Utility.subtract(this,other,false)}multiply(other){return base.Utility.multiply(this,other,false)}divide(other){return base.Utility.divide(this,other,false)}toInteger(){return this.low}toNumber(){if(this.high===0){return this.low>>>0}if(this.high===-1){return this.low}return this.high*4294967296+(this.low>>>0)}toString(radix){const r=radix||10;if(r<2||r>16){throw new RangeError("radix")}if(this.isZero){return"0"}if(this.high<0){if(this.equals(base.Int64.min)){const radix=new base.Int64(r,0);const div=this.divide(radix);const remainder=div.multiply(radix).subtract(this);return div.toString(radix)+(remainder.low>>>0).toString(radix)}return"-"+this.negate().toString(r)}if(this.high===0){return this.low.toString(radix)}return base.Utility.text(this,false,r)}};base.Int64.min=new base.Int64(0,-2147483648);base.Int64.zero=new base.Int64(0,0);base.Int64.one=new base.Int64(1,0);base.Int64.negativeOne=new base.Int64(-1,0);base.Int64.power24=new base.Int64(1<<24,0);base.Int64.max=new base.Int64(0,2147483647);base.Uint64=class Uint64{constructor(low,high){this.low=low|0;this.high=high|0}static create(value){if(isNaN(value)){return base.Uint64.zero}if(value<0){return base.Uint64.zero}if(value>=0x10000000000000000){return base.Uint64.max}if(value<0){return base.Uint64.create(-value).negate()}return new base.Uint64(value%4294967296|0,value/4294967296)}get isZero(){return this.low===0&&this.high===0}get isNegative(){return false}negate(){return this.not().add(base.Int64.one)}not(){return new base.Uint64(~this.low,~this.high)}equals(other){if(!(other instanceof base.Uint64)&&this.high>>>31===1&&other.high>>>31===1){return false}return this.high===other.high&&this.low===other.low}compare(other){if(this.equals(other)){return 0}const thisNeg=this.isNegative;const otherNeg=other.isNegative;if(thisNeg&&!otherNeg){return-1}if(!thisNeg&&otherNeg){return 1}return other.high>>>0>this.high>>>0||other.high===this.high&&other.low>>>0>this.low>>>0?-1:1}add(other){return base.Utility.add(this,other,true)}subtract(other){return base.Utility.subtract(this,other,true)}multiply(other){return base.Utility.multiply(this,other,true)}divide(other){return base.Utility.divide(this,other,true)}toInteger(){return this.low>>>0}toNumber(){if(this.high===0){return this.low>>>0}return(this.high>>>0)*4294967296+(this.low>>>0)}toString(radix){const r=radix||10;if(r<2||36<r){throw new RangeError("radix")}if(this.isZero){return"0"}if(this.high===0){return this.low.toString(radix)}return base.Utility.text(this,true,r)}};base.Utility=class{static add(a,b,unsigned){const a48=a.high>>>16;const a32=a.high&65535;const a16=a.low>>>16;const a00=a.low&65535;const b48=b.high>>>16;const b32=b.high&65535;const b16=b.low>>>16;const b00=b.low&65535;let c48=0;let c32=0;let c16=0;let c00=0;c00+=a00+b00;c16+=c00>>>16;c00&=65535;c16+=a16+b16;c32+=c16>>>16;c16&=65535;c32+=a32+b32;c48+=c32>>>16;c32&=65535;c48+=a48+b48;c48&=65535;return base.Utility._create(c16<<16|c00,c48<<16|c32,unsigned)}static subtract(a,b,unsigned){return base.Utility.add(a,b.neg