/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{formatNumber as t}from"../../intl.js";const n=/^-?(\d+)(\.(\d+))?$/i;function e(t,n){return t-n}function r(t,n){let e,r;return e=Number(t.toFixed(n)),e<t?r=e+1/10**n:(r=e,e-=1/10**n),e=Number(e.toFixed(n)),r=Number(r.toFixed(n)),[e,r]}function o(t,n,e,r,o){const i=l(t,n,e,r),u=null==i.previous||i.previous<=o,c=null==i.next||i.next<=o;return u&&c||i.previous+i.next<=2*o}function i(t){const e=String(t),r=e.match(n);if(r?.[1])return{integer:r[1].split("").length,fractional:r[3]?r[3].split("").length:0};if(e.toLowerCase().includes("e")){const t=e.split("e"),n=t[0],r=t[1];if(n&&r){const t=Number(n);let e=Number(r);const o=e>0;o||(e=Math.abs(e));const l=i(t);return o?(l.integer+=e,e>l.fractional?l.fractional=0:l.fractional-=e):(l.fractional+=e,e>l.integer?l.integer=1:l.integer-=e),l}}return{integer:0,fractional:0}}function l(t,n,e,r){const o={previous:null,next:null};if(null!=e){const r=t-e,i=n-e-r;o.previous=Math.floor(Math.abs(100*i/r))}if(null!=r){const e=r-t,i=r-n-e;o.next=Math.floor(Math.abs(100*i/e))}return o}function u(t,n={}){const l=t.slice(),{tolerance:u=2,strictBounds:c=!1,indexes:s=l.map((t,n)=>n)}=n;s.sort(e);for(let e=0;e<s.length;e++){const t=s[e],n=l[t],a=0===t?null:l[t-1],f=t===l.length-1?null:l[t+1],g=i(n).fractional;if(g){let i,s=0,m=!1;for(;s<=g&&!m;){const t=r(n,s);i=c&&0===e?t[1]:t[0],m=o(n,i,a,f,u),s++}m&&(l[t]=i)}}return l}const c={maximumFractionDigits:20};function s(n){return t(n,c)}export{s as format,i as numDigits,l as percentChange,u as round};
