kalk_web: Added integral and estimation support

This commit is contained in:
bakk 2021-05-18 23:08:38 +02:00
parent e04742695a
commit 121aafa118
7 changed files with 1518 additions and 1665 deletions

2
Cargo.lock generated
View File

@ -127,7 +127,7 @@ dependencies = [
[[package]]
name = "kalk"
version = "1.4.6"
version = "1.4.8"
dependencies = [
"lazy_static",
"regex",

View File

@ -1,6 +1,6 @@
[package]
name = "kalk"
version = "1.4.6"
version = "1.4.8"
authors = ["PaddiM8"]
edition = "2018"
readme = "README.md"

View File

@ -49,7 +49,6 @@ impl KalkNum {
self.value
}
#[wasm_bindgen(js_name = getValue)]
pub fn to_i32(&self) -> i32 {
self.value as i32
}

View File

@ -1,35 +1,35 @@
[package]
name = "kalk_cli"
version = "0.4.0"
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"
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]]
path = "src/main.rs"
name = "kalk"
path = "src/main.rs"
[dependencies]
kalk = { path = "../kalk", version = "^1.4.6" }
rustyline = "7.1.0"
ansi_term = "0.12.1"
regex = "1"
kalk = { path = "../kalk", version = "^1.4.6" }
lazy_static = "1.4.0"
regex = "1"
rustyline = "7.1.0"
seahorse = "1.1.1"
[target.'cfg(windows)'.build-dependencies]
winres = "0.1"
[package.metadata.bundle]
name = "kalk"
identifier = "net.strct.kalk"
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."
[package.metadata.bundle.bin.kalk]

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"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.",
"svelte": "src/main.ts",
"main": "public/build/bundle.js",
@ -55,7 +55,7 @@
"webpack-dev-server": "^3.11.0"
},
"dependencies": {
"@paddim8/kalk": "^1.4.5",
"@paddim8/kalk": "^1.4.8",
"shadow-selection-polyfill": "^1.1.0"
},
"browserslist": [

View File

@ -36,7 +36,7 @@
"Σ",
"⌊",
"⌈",
"ϕ",
"",
];
let numberRowValues = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"];
let outputElement: HTMLElement;
@ -55,20 +55,21 @@
function calculate(
kalk: Kalk,
input: string
): [result: string, success: boolean] {
): [result: string, estimate: string, success: boolean] {
try {
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) {
const sciNot = result.toScientificNotation();
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) {
return [err, false];
return [err, null, false];
}
}
@ -84,12 +85,16 @@
href="https://kalk.netlify.app/#usage"
target="blank">Link to usage guide</a>`;
} else {
const [result, success] = calculate(
const [result, estimate, success] = calculate(
kalk,
input.replace(/\s+/g, "") // Temporary fix, since it for some reason complains about spaces on chrome
);
const resultWithEstimate = estimate
? result + " ≈ " + estimate
: result;
output = success
? highlight(result)[0]
? highlight(resultWithEstimate)[0]
: `<span style="color: ${errorcolor}">${result}</span>`;
}
@ -273,7 +278,7 @@
let result = input;
let offset = 0;
result = result.replace(
/(?<identifier>[^!-@\s_|^⌊⌋⌈⌉]+(_\d+)?)|(?<op>[+\-/*%^!])/g,
/(?<identifier>[^!-@\s_|^⌊⌋⌈⌉]+(_\d+)?)|(?<op>[+\-/*%^!])/g,
(substring, identifier, _, op) => {
if (identifier) {
let newSubstring: string = substring;