/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
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,$ as i,r as a,J as s,L as f,H 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,(a,s,f)=>{t(f,1,2,r,n);const c=f[0];if(N(c))return c;if(null===c)return 0;if(u(c)||e(c)||o(c))return c.toNumber();if(p(c))return Number(c);if(M(c))return NaN;if(""===c)return Number(c);if(void 0===c)return Number(c);if(b(c)){if(void 0!==f[1]){let r=i(f[1],"‰","");return r=i(r,"¤",""),h(c,{pattern:r})}return Number(c.trim())}return Number(c)})},g.abs=function(r,n){return d(r,n,(u,e,o)=>(t(o,1,1,r,n),Math.abs(a(o[0]))))},g.acos=function(r,n){return d(r,n,(u,e,o)=>(t(o,1,1,r,n),Math.acos(a(o[0]))))},g.asin=function(r,n){return d(r,n,(u,e,o)=>(t(o,1,1,r,n),Math.asin(a(o[0]))))},g.atan=function(r,n){return d(r,n,(u,e,o)=>(t(o,1,1,r,n),Math.atan(a(o[0]))))},g.atan2=function(r,n){return d(r,n,(u,e,o)=>(t(o,2,2,r,n),Math.atan2(a(o[0]),a(o[1]))))},g.ceil=function(r,n){return d(r,n,(u,e,o)=>{if(t(o,1,2,r,n),2===o.length){let r=a(o[1]);return isNaN(r)&&(r=0),l("ceil",a(o[0]),-1*r)}return Math.ceil(a(o[0]))})},g.round=function(r,n){return d(r,n,(u,e,o)=>{if(t(o,1,2,r,n),2===o.length){let r=a(o[1]);return isNaN(r)&&(r=0),l("round",a(o[0]),-1*r)}return Math.round(a(o[0]))})},g.floor=function(r,n){return d(r,n,(u,e,o)=>{if(t(o,1,2,r,n),2===o.length){let r=a(o[1]);return isNaN(r)&&(r=0),l("floor",a(o[0]),-1*r)}return Math.floor(a(o[0]))})},g.cos=function(r,n){return d(r,n,(u,e,o)=>(t(o,1,1,r,n),Math.cos(a(o[0]))))},g.isnan=function(r,n){return d(r,n,(u,e,o)=>(t(o,1,1,r,n),"number"==typeof o[0]&&isNaN(o[0])))},g.exp=function(r,n){return d(r,n,(u,e,o)=>(t(o,1,1,r,n),Math.exp(a(o[0]))))},g.log=function(r,n){return d(r,n,(u,e,o)=>(t(o,1,1,r,n),Math.log(a(o[0]))))},g.pow=function(r,n){return d(r,n,(u,e,o)=>(t(o,2,2,r,n),a(o[0])**a(o[1])))},g.random=function(r,n){return d(r,n,(u,e,o)=>(t(o,0,0,r,n),Math.random()))},g.sin=function(r,n){return d(r,n,(u,e,o)=>(t(o,1,1,r,n),Math.sin(a(o[0]))))},g.sqrt=function(r,n){return d(r,n,(u,e,o)=>(t(o,1,1,r,n),Math.sqrt(a(o[0]))))},g.tan=function(r,n){return d(r,n,(u,e,o)=>(t(o,1,1,r,n),Math.tan(a(o[0]))))},g.isempty=function(u,e){return d(u,e,(u,e,o)=>{if(t(o,1,2,u,e),o.length>=2&&!p(o[1]))throw new n(u,"InvalidParameter",e);return s(o[1],!1)?r(o[0]):f(o[0])})},g.boolean=function(r,n){return d(r,n,(u,e,o)=>{t(o,1,1,r,n);const i=o[0];return c(i)})},g.constrain=function(r,n){return d(r,n,(u,e,o)=>{t(o,3,3,r,n);const i=a(o[1]),s=a(o[2]);if(M(o[0])){const r=[];for(const n of o[0])r.push(j(n,i,s));return r}if(m(o[0])){const r=[];for(let n=0;n<o[0].length();n++)r.push(j(o[0].get(n),i,s));return r}return j(o[0],i,s)})}}export{g as registerFunctions};
