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