From 47aa362b888259954214952f675e0cf93b5f8941 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Wed, 15 Jan 2025 15:45:20 +1100 Subject: launcher: math derive short form + help --- services/math.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'services/math.ts') diff --git a/services/math.ts b/services/math.ts index 2c7fabd..c66798c 100644 --- a/services/math.ts +++ b/services/math.ts @@ -95,7 +95,12 @@ export default class Math extends GObject.Object { let result: string, icon: string; try { - if (equation.includes("=")) { + if (equation.startsWith("help")) { + equation = "Help"; + result = + "This is a calculator powered by Math.js.\nAvailable functions:\n\thelp: show help\n\tclear: clear history\n\t = : sets to \n\tsimplify : simplifies \n\tderive : derives with respect to \n\tdd : short form of derive\n\trationalize : rationalizes \n\t: evaluates \nSee the documentation for syntax and inbuilt functions."; + icon = "help"; + } else if (equation.includes("=")) { const [left, right] = equation.split("="); try { this.#variables[left.trim()] = simplify(right).toString(); @@ -107,10 +112,11 @@ export default class Math extends GObject.Object { } else if (equation.startsWith("simplify")) { result = simplify(equation.slice(8), this.#variables).toString(); icon = "function"; - } else if (equation.startsWith("derive")) { - const respectTo = equation.split(" ")[1]; - if (!respectTo) throw new Error("Format: derive "); - result = derivative(equation.slice(7 + respectTo.length), respectTo).toString(); + } else if (equation.startsWith("derive") || equation.startsWith("dd")) { + const isShortForm = equation.startsWith("dd"); + const respectTo = isShortForm ? equation.split(" ")[0].slice(2) : equation.split(" ")[1]; + if (!respectTo) throw new Error(`Format: ${isShortForm ? "dd" : "derive "} `); + result = derivative(equation.slice((isShortForm ? 2 : 7) + respectTo.length), respectTo).toString(); icon = "function"; } else if (equation.startsWith("rationalize")) { result = rationalize(equation.slice(11), this.#variables).toString(); -- cgit v1.2.3-freya