const e=require("../../../_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/defineProperty.js"),t=require("./supportUtil.js"),n=require("./numberUtil.js");function r(e){return!e&&e!==0&&!Number.isNaN(e)||!String(e).trim()}var i=class t{constructor(t){if(e.default(this,`origin`,``),e.default(this,`number`,void 0),e.default(this,`empty`,void 0),r(t)){this.empty=!0;return}this.origin=String(t),this.number=Number(t)}negate(){return new t(-this.toNumber())}add(e){if(this.isInvalidate())return new t(e);let r=Number(e);if(Number.isNaN(r))return this;let i=this.number+r;if(i>2**53-1)return new t(2**53-1);if(i<-(2**53-1))return new t(-(2**53-1));let a=Math.max(n.getNumberPrecision(this.number),n.getNumberPrecision(r));return new t(i.toFixed(a))}isEmpty(){return this.empty}isNaN(){return Number.isNaN(this.number)}isInvalidate(){return this.isEmpty()||this.isNaN()}equals(e){return this.toNumber()===e?.toNumber()}lessEquals(e){return this.add(e.negate().toString()).toNumber()<=0}toNumber(){return this.number}toString(e=!0){return e?this.isInvalidate()?``:n.num2str(this.number):this.origin}},a=class t{constructor(t){if(e.default(this,`origin`,``),e.default(this,`negative`,void 0),e.default(this,`integer`,void 0),e.default(this,`decimal`,void 0),e.default(this,`decimalLen`,void 0),e.default(this,`empty`,void 0),e.default(this,`nan`,void 0),r(t)){this.empty=!0;return}if(this.origin=String(t),t===`-`||Number.isNaN(t)){this.nan=!0;return}let i=t;if(n.isE(i)&&(i=Number(i)),i=typeof i==`string`?i:n.num2str(i),n.validateNumber(i)){let e=n.trimNumber(i);this.negative=e.negative;let t=e.trimStr.split(`.`);this.integer=BigInt(t[0]);let r=t[1]||`0`;this.decimal=BigInt(r),this.decimalLen=r.length}else this.nan=!0}getMark(){return this.negative?`-`:``}getIntegerStr(){return this.integer.toString()}getDecimalStr(){return this.decimal.toString().padStart(this.decimalLen,`0`)}alignDecimal(e){let t=`${this.getMark()}${this.getIntegerStr()}${this.getDecimalStr().padEnd(e,`0`)}`;return BigInt(t)}negate(){let e=new t(this.toString());return e.negative=!e.negative,e}add(e){if(this.isInvalidate())return new t(e);let r=new t(e);if(r.isInvalidate())return this;let i=Math.max(this.getDecimalStr().length,r.getDecimalStr().length),{negativeStr:a,trimStr:o}=n.trimNumber((this.alignDecimal(i)+r.alignDecimal(i)).toString()),s=`${a}${o.padStart(i+1,`0`)}`;return new t(`${s.slice(0,-i)}.${s.slice(-i)}`)}isEmpty(){return this.empty}isNaN(){return this.nan}isInvalidate(){return this.isEmpty()||this.isNaN()}equals(e){return this.toString()===e?.toString()}lessEquals(e){return this.add(e.negate().toString()).toNumber()<=0}toNumber(){return this.isNaN()?NaN:Number(this.toString())}toString(e=!0){return e?this.isInvalidate()?``:n.trimNumber(`${this.getMark()}${this.getIntegerStr()}.${this.getDecimalStr()}`).fullStr:this.origin}};function o(e){return t.supportBigInt()?new a(e):new i(e)}function s(e,t,r,i=!1){if(e===``)return``;let{negativeStr:a,integerStr:c,decimalStr:l}=n.trimNumber(e),u=`${t}${l}`,d=`${a}${c}`;if(r>=0){let n=Number(l[r]);return n>=5&&!i?s(o(e).add(`${a}0.${`0`.repeat(r)}${10-n}`).toString(),t,r,i):r===0?d:`${d}${t}${l.padEnd(r,`0`).slice(0,r)}`}return u===`.0`?d:`${d}${u}`}exports.BigIntDecimal=a,exports.NumberDecimal=i,exports.default=o,exports.toFixed=s;