From 047d41a20e38fb23154031180602a1f0d62119f9 Mon Sep 17 00:00:00 2001 From: Ean Milligan Date: Tue, 29 Apr 2025 04:11:06 -0400 Subject: [PATCH] support all one arg Math functions --- src/solver/rollUtils.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/solver/rollUtils.ts b/src/solver/rollUtils.ts index 3f1fecb..02ed927 100644 --- a/src/solver/rollUtils.ts +++ b/src/solver/rollUtils.ts @@ -7,8 +7,15 @@ import { RollModifiers } from '../mod.d.ts'; import { DPercentConf, ReturnData, RollSet } from './solver.d.ts'; +type MathFunction = (arg: number) => number; export const loggingEnabled = false; -export const legalMath = [Math.abs, Math.ceil, Math.floor, Math.round, Math.sqrt, Math.cbrt]; +export const legalMath: MathFunction[] = []; +(Object.getOwnPropertyNames(Math) as (keyof Math)[]).forEach((propName) => { + const mathProp = Math[propName]; + if (typeof mathProp === 'function' && mathProp.length === 1) { + legalMath.push(mathProp as MathFunction); + } +}); export const legalMathOperators = legalMath.map((oper) => oper.name); // genRoll(size) returns number