mirror of
https://github.com/PaddiM8/kalker.git
synced 2024-12-13 10:00:51 +01:00
kalk_web: Added integral and estimation support
This commit is contained in:
parent
4acb1b7304
commit
3942aacd6a
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -127,7 +127,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kalk"
|
name = "kalk"
|
||||||
version = "1.4.6"
|
version = "1.4.8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"regex",
|
"regex",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "kalk"
|
name = "kalk"
|
||||||
version = "1.4.6"
|
version = "1.4.8"
|
||||||
authors = ["PaddiM8"]
|
authors = ["PaddiM8"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@ -49,7 +49,6 @@ impl KalkNum {
|
|||||||
self.value
|
self.value
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen(js_name = getValue)]
|
|
||||||
pub fn to_i32(&self) -> i32 {
|
pub fn to_i32(&self) -> i32 {
|
||||||
self.value as i32
|
self.value as i32
|
||||||
}
|
}
|
||||||
|
@ -1,35 +1,35 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "kalk_cli"
|
|
||||||
version = "0.4.0"
|
|
||||||
authors = ["PaddiM8"]
|
authors = ["PaddiM8"]
|
||||||
edition = "2018"
|
|
||||||
readme = "../README.md"
|
|
||||||
description = "A calculator that supports user-defined functions, variables and units, and can handle fairly ambiguous syntax."
|
|
||||||
repository = "https://github.com/PaddiM8/kalk"
|
|
||||||
license = "MIT"
|
|
||||||
keywords = ["math", "calculator", "cli", "command-line"]
|
|
||||||
categories = ["mathematics", "command-line-utilities"]
|
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
|
categories = ["mathematics", "command-line-utilities"]
|
||||||
|
description = "A calculator that supports user-defined functions, variables and units, and can handle fairly ambiguous syntax."
|
||||||
|
edition = "2018"
|
||||||
|
keywords = ["math", "calculator", "cli", "command-line"]
|
||||||
|
license = "MIT"
|
||||||
|
name = "kalk_cli"
|
||||||
|
readme = "../README.md"
|
||||||
|
repository = "https://github.com/PaddiM8/kalk"
|
||||||
|
version = "0.4.0"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
path = "src/main.rs"
|
|
||||||
name = "kalk"
|
name = "kalk"
|
||||||
|
path = "src/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
kalk = { path = "../kalk", version = "^1.4.6" }
|
|
||||||
rustyline = "7.1.0"
|
|
||||||
ansi_term = "0.12.1"
|
ansi_term = "0.12.1"
|
||||||
regex = "1"
|
kalk = { path = "../kalk", version = "^1.4.6" }
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
|
regex = "1"
|
||||||
|
rustyline = "7.1.0"
|
||||||
seahorse = "1.1.1"
|
seahorse = "1.1.1"
|
||||||
|
|
||||||
[target.'cfg(windows)'.build-dependencies]
|
[target.'cfg(windows)'.build-dependencies]
|
||||||
winres = "0.1"
|
winres = "0.1"
|
||||||
|
|
||||||
[package.metadata.bundle]
|
[package.metadata.bundle]
|
||||||
name = "kalk"
|
|
||||||
identifier = "net.strct.kalk"
|
|
||||||
icon = ["../res/icon*"]
|
icon = ["../res/icon*"]
|
||||||
|
identifier = "net.strct.kalk"
|
||||||
|
name = "kalk"
|
||||||
short_description = "A calculator that supports user-defined functions, variables and units, and can handle fairly ambiguous syntax."
|
short_description = "A calculator that supports user-defined functions, variables and units, and can handle fairly ambiguous syntax."
|
||||||
|
|
||||||
[package.metadata.bundle.bin.kalk]
|
[package.metadata.bundle.bin.kalk]
|
||||||
|
3121
kalk_web/package-lock.json
generated
3121
kalk_web/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@paddim8/kalk-component",
|
"name": "@paddim8/kalk-component",
|
||||||
"version": "1.0.14",
|
"version": "1.0.15",
|
||||||
"description": "A Svelte component for kalk, a calculator that supports user-defined functions and variables.",
|
"description": "A Svelte component for kalk, a calculator that supports user-defined functions and variables.",
|
||||||
"svelte": "src/main.ts",
|
"svelte": "src/main.ts",
|
||||||
"main": "public/build/bundle.js",
|
"main": "public/build/bundle.js",
|
||||||
@ -55,7 +55,7 @@
|
|||||||
"webpack-dev-server": "^3.11.0"
|
"webpack-dev-server": "^3.11.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@paddim8/kalk": "^1.4.5",
|
"@paddim8/kalk": "^1.4.8",
|
||||||
"shadow-selection-polyfill": "^1.1.0"
|
"shadow-selection-polyfill": "^1.1.0"
|
||||||
},
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
"Σ",
|
"Σ",
|
||||||
"⌊",
|
"⌊",
|
||||||
"⌈",
|
"⌈",
|
||||||
"ϕ",
|
"∫",
|
||||||
];
|
];
|
||||||
let numberRowValues = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"];
|
let numberRowValues = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"];
|
||||||
let outputElement: HTMLElement;
|
let outputElement: HTMLElement;
|
||||||
@ -55,20 +55,21 @@
|
|||||||
function calculate(
|
function calculate(
|
||||||
kalk: Kalk,
|
kalk: Kalk,
|
||||||
input: string
|
input: string
|
||||||
): [result: string, success: boolean] {
|
): [result: string, estimate: string, success: boolean] {
|
||||||
try {
|
try {
|
||||||
if (!kalkContext) kalkContext = new kalk.Context();
|
if (!kalkContext) kalkContext = new kalk.Context();
|
||||||
const result = kalkContext.evaluate(input) ?? "";
|
const result = kalkContext.evaluate(input);
|
||||||
|
const estimate = result.estimate();
|
||||||
if (result && result.getValue() != 0) {
|
if (result && result.getValue() != 0) {
|
||||||
const sciNot = result.toScientificNotation();
|
const sciNot = result.toScientificNotation();
|
||||||
if (sciNot.exponent > 7 || sciNot.exponent < -6) {
|
if (sciNot.exponent > 7 || sciNot.exponent < -6) {
|
||||||
return [sciNot.toString(), true];
|
return [sciNot.toString(), estimate, true];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return [result?.toString(), true];
|
return [result?.toString(), estimate, true];
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return [err, false];
|
return [err, null, false];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,12 +85,16 @@
|
|||||||
href="https://kalk.netlify.app/#usage"
|
href="https://kalk.netlify.app/#usage"
|
||||||
target="blank">Link to usage guide</a>`;
|
target="blank">Link to usage guide</a>`;
|
||||||
} else {
|
} else {
|
||||||
const [result, success] = calculate(
|
const [result, estimate, success] = calculate(
|
||||||
kalk,
|
kalk,
|
||||||
input.replace(/\s+/g, "") // Temporary fix, since it for some reason complains about spaces on chrome
|
input.replace(/\s+/g, "") // Temporary fix, since it for some reason complains about spaces on chrome
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const resultWithEstimate = estimate
|
||||||
|
? result + " ≈ " + estimate
|
||||||
|
: result;
|
||||||
output = success
|
output = success
|
||||||
? highlight(result)[0]
|
? highlight(resultWithEstimate)[0]
|
||||||
: `<span style="color: ${errorcolor}">${result}</span>`;
|
: `<span style="color: ${errorcolor}">${result}</span>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,7 +278,7 @@
|
|||||||
let result = input;
|
let result = input;
|
||||||
let offset = 0;
|
let offset = 0;
|
||||||
result = result.replace(
|
result = result.replace(
|
||||||
/(?<identifier>[^!-@\s_|^⌊⌋⌈⌉]+(_\d+)?)|(?<op>[+\-/*%^!])/g,
|
/(?<identifier>[^!-@\s_|^⌊⌋⌈⌉≈]+(_\d+)?)|(?<op>[+\-/*%^!≈])/g,
|
||||||
(substring, identifier, _, op) => {
|
(substring, identifier, _, op) => {
|
||||||
if (identifier) {
|
if (identifier) {
|
||||||
let newSubstring: string = substring;
|
let newSubstring: string = substring;
|
||||||
|
Loading…
Reference in New Issue
Block a user