Compute Modes API
Configuration
javascript
import { set_config, get_config } from "a-calc";
set_config({ _compute_mode: "bigint" });
get_config("_compute_mode"); // 'bigint'
// Division precision (BigInt mode only)
set_config({ _div_precision: 30 });WASM Functions
load_wasm()
javascript
import { load_wasm } from "a-calc";
await load_wasm();
// or with custom path
await load_wasm("/path/to/wasm_calc_bg.wasm");is_wasm_loaded()
javascript
import { is_wasm_loaded } from "a-calc";
is_wasm_loaded(); // true/falsewcalc(expr)
javascript
import { load_wasm, wcalc } from "a-calc";
await load_wasm();
wcalc("1 + 2 * 3"); // "7"
wcalc("sqrt(16) + pow(2, 3)"); // "12"r* Functions (Follow _compute_mode)
String in, string out. Automatically use the current compute mode.
javascript
import { radd, rsub, rmul, rdiv, rmod, rpow, ridiv } from "a-calc";
import { rabs, rneg, rsqrt, rfloor, rceil, rtrunc, rround } from "a-calc";
import { rmax, rmin, rcompare, req, rlt, rgt, rlte, rgte } from "a-calc";
import { rsin, rcos, rtan, rexp, rln, rlog10 } from "a-calc";
radd("0.1", "0.2"); // "0.3"
rmul("0.1", "0.2"); // "0.02"
rfloor("3.7"); // "3"
rmax("3", "5"); // "5"d* Functions (Always Decimal)
javascript
import { dadd, dmul, ddiv } from "a-calc";
dadd("0.1", "0.2"); // "0.3"b* Functions (Always BigInt)
javascript
import { badd, bmul } from "a-calc";
badd("0.1", "0.2"); // "0.3"w* Functions (Always WASM)
javascript
import { load_wasm, wadd, wmul } from "a-calc";
await load_wasm();
wadd("0.1", "0.2"); // "0.3"set_config / get_config / reset_config
javascript
import { set_config, get_config, reset_config } from "a-calc";
set_config({ _error: "-", _angle_unit: "rad" });
get_config("_error"); // '-'
get_config(); // full config object
reset_config("_error"); // reset one
reset_config(["_error", "_angle_unit"]); // reset multiple
reset_config(); // reset allAll Config Options
| Option | Type | Default | Description |
|---|---|---|---|
_compute_mode | 'decimal'|'bigint'|'wasm' | 'decimal' | Compute engine |
_div_precision | number | 20 | BigInt division precision |
_error | any | '-' | Error return value |
_debug_console | boolean | true | Print debug to console |
_angle_unit | 'deg'|'rad' | 'deg' | Angle unit |
_fmt | string | - | Global default format |
_unit_convert_out | object | - | Unit conversion map (output key) |
_unit_default_out | string|string[] | - | Default output unit |
_unit_default_in | string|string[] | - | Default input unit |
_unit_default_position | 'before'|'after'|'middle' | - | Default unit position |
_unit_position_map | object | - | Unit-to-position map |
_unit_thousands_map | object | - | Unit-to-thousands-preset map |
_unit_compact_map | object | - | Unit-to-compact-preset map |
_thousands | object | - | Custom thousands presets |
_compact | object | - | Custom compact presets |
_compact_default | string | - | Default compact preset name |
_thousands_default | string | - | Default thousands preset name |
_fmt_groups | object | - | Format group definitions |