/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{isEmpty as r}from"../containerUtils.js";import{ArcadeExecutionError as n}from"../executionError.js";import{B as t,e as u,g as e,f as o,a1 as i,r as a,O as s,Q as f,N as c,j as m}from"../../chunks/languageUtils.js";import{decimalAdjust as l}from"../../core/mathUtils.js";import{parse as h}from"../../core/number.js";import{isNumber as N,isBoolean as p,isArray as M,isString as b}from"../../support/guards.js";function g(g,d){function j(r,n,t){const u=a(r);return isNaN(u)?u:isNaN(n)||isNaN(t)||n>t?NaN:u<n?n:u>t?t:u}g.number=function(r,n){return d(r,n,(r,a,s)=>{t(s,1,2,n);const f=s[0];if(N(f))return f;if(null===f)return 0;if(u(f)||e(f)||o(f))return f.toNumber();if(p(f))return Number(f);if(M(f))return NaN;if(""===f)return Number(f);if(void 0===f)return Number(f);if(b(f)){if(void 0!==s[1]){let r=i(s[1],"‰","");return r=i(r,"¤",""),h(f,{pattern:r})}return Number(f.trim())}return Number(f)})},g.abs=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.abs(a(e[0]))))},g.acos=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.acos(a(e[0]))))},g.asin=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.asin(a(e[0]))))},g.atan=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.atan(a(e[0]))))},g.atan2=function(r,n){return d(r,n,(r,u,e)=>(t(e,2,2,n),Math.atan2(a(e[0]),a(e[1]))))},g.ceil=function(r,n){return d(r,n,(r,u,e)=>{if(t(e,1,2,n),2===e.length){let r=a(e[1]);return isNaN(r)&&(r=0),l("ceil",a(e[0]),-1*r)}return Math.ceil(a(e[0]))})},g.round=function(r,n){return d(r,n,(r,u,e)=>{if(t(e,1,2,n),2===e.length){let r=a(e[1]);return isNaN(r)&&(r=0),l("round",a(e[0]),-1*r)}return Math.round(a(e[0]))})},g.floor=function(r,n){return d(r,n,(r,u,e)=>{if(t(e,1,2,n),2===e.length){let r=a(e[1]);return isNaN(r)&&(r=0),l("floor",a(e[0]),-1*r)}return Math.floor(a(e[0]))})},g.cos=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.cos(a(e[0]))))},g.isnan=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),"number"==typeof e[0]&&isNaN(e[0])))},g.exp=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.exp(a(e[0]))))},g.log=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.log(a(e[0]))))},g.pow=function(r,n){return d(r,n,(r,u,e)=>(t(e,2,2,n),a(e[0])**a(e[1])))},g.random=function(r,n){return d(r,n,(r,u,e)=>(t(e,0,0,n),Math.random()))},g.sin=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.sin(a(e[0]))))},g.sqrt=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.sqrt(a(e[0]))))},g.tan=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.tan(a(e[0]))))},g.isempty=function(u,e){return d(u,e,(u,e,o)=>{if(t(o,1,2,e),o.length>=2&&!p(o[1]))throw new n("InvalidParameter",e);return s(o[1],!1)?r(o[0]):f(o[0])})},g.boolean=function(r,n){return d(r,n,(r,u,e)=>{t(e,1,1,n);const o=e[0];return c(o)})},g.constrain=function(r,n){return d(r,n,(r,u,e)=>{t(e,3,3,n);const o=a(e[1]),i=a(e[2]);if(M(e[0])){const r=[];for(const n of e[0])r.push(j(n,o,i));return r}if(m(e[0])){const r=[];for(let n=0;n<e[0].length();n++)r.push(j(e[0].get(n),o,i));return r}return j(e[0],o,i)})}}export{g as registerFunctions};
