From 3f0dfb785c75b12100d64f0dc3615c2d38cfb3dd Mon Sep 17 00:00:00 2001 From: Omid Mortazavi <47784811+somidmor@users.noreply.github.com> Date: Thu, 22 Feb 2024 16:47:13 -0800 Subject: [PATCH] add hyperbolic tokens(sinh, cosh, ...), mode(%) function, sec, csc, cot --- Sources/MathParser/MathParser.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Sources/MathParser/MathParser.swift b/Sources/MathParser/MathParser.swift index cec3b60..15f737a 100644 --- a/Sources/MathParser/MathParser.swift +++ b/Sources/MathParser/MathParser.swift @@ -75,13 +75,17 @@ final public class MathParser { */ public static let defaultUnaryFunctions: UnaryFunctionDict = [ "sin": sin, "asin": asin, "cos": cos, "acos": acos, "tan": tan, "atan": atan, - "log10": log10, "ln": log, "loge": log, "log2": log2, "exp": exp, + "sinh": sinh, "asinh": asinh, "cosh": cosh, "acosh": acosh, "tanh": tanh, "atanh": atanh, + "log": log10, "log10": log10, "ln": log, "loge": log, "log2": log2, "exp": exp, "ceil": ceil, "floor": floor, "round": round, "sqrt": sqrt, "√": sqrt, "cbrt": cbrt, // cube root, "abs": abs, "sgn": { $0 < 0 ? -1 : $0 > 0 ? 1 : 0 }, - "!": { factorial($0) } + "!": { factorial($0) }, + "sec": { 1 / cos($0) }, + "csc": { 1 / sin($0) }, + "cot": { 1 / tan($0) } ] /** @@ -97,7 +101,8 @@ final public class MathParser { public static let defaultBinaryFunctions: BinaryFunctionDict = [ "atan2": atan2, "hypot": hypot, - "pow": pow // Redundant since we support x^b expressions + "pow": pow, // Redundant since we support x^b expressions + "mod": { $0.truncatingRemainder(dividingBy: $1) } ] /// Symbol/variable mapping to use during parsing and perhaps evaluation