UNPKG

gnablib

Version:

A lean, zero dependency library to provide a useful base for your project.

2 lines 2.6 kB
/*! Copyright 2025 the gnablib contributors MPL-1.1 */ import{sLen as t}from"../../safe/safe.js";import{AInt as r}from"./_AInt.js";export class I64 extends r{constructor(t,r,e="I64"){super(t,r,2,e)}static fromInt(t){return new I64(r._fromInt(2,t),0)}static fromI32s(...t){const e=r._fromSignedSet(2,t);return new I64(e,0)}static fromBytesBE(t,r=0){return new I64(this._fromBytesBE(8,t,r),0)}static mount(r,e=0){return t("arr",r).atLeast(e+2).throwNot(),new I64(r,e)}clone(){return new I64(this._arr.slice(this._pos,this._pos+2),0)}mut(){const t=this._arr.slice(this._pos,this._pos+2);return I64Mut.mount(t,0)}lShift(t){const r=this.clone();return r._lShiftEq(t),r}rShift(t){const r=this.clone();return r._rShiftEq(t,this.negative?-1:0),r}lRot(t){const r=this.clone();return r._lRotEq(t),r}rRot(t){const r=this.clone();return r._lRotEq(64-t),r}xor(t){const r=this.clone();return r._xorEq(t),r}or(t){const r=this.clone();return r._orEq(t),r}and(t){const r=this.clone();return r._andEq(t),r}not(){const t=this.clone();return t._notEq(),t}add(t){const r=this.clone();return r._addEq(t),r}sub(t){const r=this.clone();return r._subEq(t),r}mul(t){const r=this._mul(t);return new I64(r,0)}get negative(){return this._arr[this._pos+this.size32-1]>>>31==1}abs(){const t=this.clone();return this.negative&&t._negEq(),t}eq(t){return super.eq(t)}gt(t){return this.negative!==t.negative?t.negative:super.gt(t)}gte(t){return this.negative!==t.negative?t.negative:super.gte(t)}lt(t){return this.negative!==t.negative?this.negative:super.lt(t)}lte(t){return this.negative!==t.negative?this.negative:super.lte(t)}static get zero(){return e}}const e=I64.mount(new Uint32Array(2),0);export class I64Mut extends I64{constructor(t,r){super(t,r,"I64Mut")}set(t){return super._setValue(t),this}zero(){return super._setZero(),this}static fromInt(t){return new I64Mut(r._fromInt(2,t),0)}static fromI32s(...t){const e=r._fromSignedSet(2,t);return new I64Mut(e,0)}static fromBytesBE(t,r=0){return new I64Mut(this._fromBytesBE(8,t,r),0)}static mount(r,e=0){return t("arr",r).atLeast(e+2).throwNot(),new I64Mut(r,e)}lShiftEq(t){return this._lShiftEq(t),this}lRotEq(t){return this._lRotEq(t),this}rShiftEq(t){return this._rShiftEq(t,this.negative?-1:0),this}rRotEq(t){return this._lRotEq(64-t),this}xorEq(t){return this._xorEq(t),this}orEq(t){return this._orEq(t),this}andEq(t){return this._andEq(t),this}notEq(){return this._notEq(),this}addEq(t){return this._addEq(t),this}subEq(t){return this._subEq(t),this}mulEq(t){const r=this._mul(t);return this._arr.set(r,this._pos),this}absEq(){return this.negative&&this._negEq(),this}}