"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("./numberUtil.js"),S=require("./supportUtil.js");function N(i){return!i&&i!==0&&!Number.isNaN(i)||!String(i).trim()}class u{origin="";number;empty;constructor(t){if(N(t)){this.empty=!0;return}this.origin=String(t),this.number=Number(t)}negate(){return new u(-this.toNumber())}add(t){if(this.isInvalidate())return new u(t);const e=Number(t);if(Number.isNaN(e))return this;const r=this.number+e;if(r>Number.MAX_SAFE_INTEGER)return new u(Number.MAX_SAFE_INTEGER);if(r<Number.MIN_SAFE_INTEGER)return new u(Number.MIN_SAFE_INTEGER);const s=Math.max(n.getNumberPrecision(this.number),n.getNumberPrecision(e));return new u(r.toFixed(s))}isEmpty(){return this.empty}isNaN(){return Number.isNaN(this.number)}isInvalidate(){return this.isEmpty()||this.isNaN()}equals(t){return this.toNumber()===t?.toNumber()}lessEquals(t){return this.add(t.negate().toString()).toNumber()<=0}toNumber(){return this.number}toString(t=!0){return t?this.isInvalidate()?"":n.num2str(this.number):this.origin}}class a{origin="";negative;integer;decimal;decimalLen;empty;nan;constructor(t){if(N(t)){this.empty=!0;return}if(this.origin=String(t),t==="-"||Number.isNaN(t)){this.nan=!0;return}let e=t;if(n.isE(e)&&(e=Number(e)),e=typeof e=="string"?e:n.num2str(e),n.validateNumber(e)){const r=n.trimNumber(e);this.negative=r.negative;const s=r.trimStr.split(".");this.integer=BigInt(s[0]);const m=s[1]||"0";this.decimal=BigInt(m),this.decimalLen=m.length}else this.nan=!0}getMark(){return this.negative?"-":""}getIntegerStr(){return this.integer.toString()}getDecimalStr(){return this.decimal.toString().padStart(this.decimalLen,"0")}alignDecimal(t){const e=`${this.getMark()}${this.getIntegerStr()}${this.getDecimalStr().padEnd(t,"0")}`;return BigInt(e)}negate(){const t=new a(this.toString());return t.negative=!t.negative,t}add(t){if(this.isInvalidate())return new a(t);const e=new a(t);if(e.isInvalidate())return this;const r=Math.max(this.getDecimalStr().length,e.getDecimalStr().length),s=this.alignDecimal(r),m=e.alignDecimal(r),o=(s+m).toString(),{negativeStr:c,trimStr:g}=n.trimNumber(o),h=`${c}${g.padStart(r+1,"0")}`;return new a(`${h.slice(0,-r)}.${h.slice(-r)}`)}isEmpty(){return this.empty}isNaN(){return this.nan}isInvalidate(){return this.isEmpty()||this.isNaN()}equals(t){return this.toString()===t?.toString()}lessEquals(t){return this.add(t.negate().toString()).toNumber()<=0}toNumber(){return this.isNaN()?Number.NaN:Number(this.toString())}toString(t=!0){return t?this.isInvalidate()?"":n.trimNumber(`${this.getMark()}${this.getIntegerStr()}.${this.getDecimalStr()}`).fullStr:this.origin}}function l(i){return S.supportBigInt()?new a(i):new u(i)}function d(i,t,e,r=!1){if(i==="")return"";const{negativeStr:s,integerStr:m,decimalStr:o}=n.trimNumber(i),c=`${t}${o}`,g=`${s}${m}`;if(e>=0){const h=Number(o[e]);if(h>=5&&!r){const b=l(i).add(`${s}0.${"0".repeat(e)}${10-h}`);return d(b.toString(),t,e,r)}return e===0?g:`${g}${t}${o.padEnd(e,"0").slice(0,e)}`}return c===".0"?g:`${g}${c}`}exports.BigIntDecimal=a;exports.NumberDecimal=u;exports.default=l;exports.toFixed=d;
