summaryrefslogtreecommitdiff
path: root/services/math.ts
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-01-15 15:45:20 +1100
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-01-15 15:45:20 +1100
commit47aa362b888259954214952f675e0cf93b5f8941 (patch)
treeb4c9ab1284fc2eb4fdbdf23dc11215aac588c58a /services/math.ts
parenttooltip: add namespace prefix (diff)
downloadcaelestia-shell-47aa362b888259954214952f675e0cf93b5f8941.tar.gz
caelestia-shell-47aa362b888259954214952f675e0cf93b5f8941.tar.bz2
caelestia-shell-47aa362b888259954214952f675e0cf93b5f8941.zip
launcher: math derive short form + help
Diffstat (limited to 'services/math.ts')
-rw-r--r--services/math.ts16
1 files changed, 11 insertions, 5 deletions
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<x> = <equation>: sets <x> to <equation>\n\tsimplify <equation>: simplifies <equation>\n\tderive <x> <equation>: derives <equation> with respect to <x>\n\tdd<x> <equation>: short form of derive\n\trationalize <equation>: rationalizes <equation>\n\t<equation>: evaluates <equation>\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 <respect-to> <equation>");
- 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 "}<respect-to> <equation>`);
+ 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();