diff --git a/src/engine/evaluator.ts b/src/engine/evaluator.ts index 67df2c4..238b3c1 100644 --- a/src/engine/evaluator.ts +++ b/src/engine/evaluator.ts @@ -1,6 +1,6 @@ // Walks the AST with the document context (variables, line results for // sum/avg/prev) and produces unit-aware values. -import { Decimal, EvalError, Quantity, Unit, Value, XRefError, qty, pct } from "./types"; +import { Decimal, EvalError, PI, Quantity, Unit, Value, XRefError, qty, pct } from "./types"; import { Node, ConvTarget } from "./parser"; import { Registry } from "./registry"; import { resolveZone, startOfToday, addToDate, isCalendarUnit } from "./datetime"; @@ -28,7 +28,6 @@ export interface EvalCtx { export type XRefResolution = { ok: true; value: Value } | { ok: false; reason: string }; export type XRefResolver = (sheet: string, key: string) => XRefResolution; -const PI = new Decimal("3.14159265358979323846264338327950288419716939937510"); const E = new Decimal("2.71828182845904523536028747135266249775724709369995"); export function evaluate(node: Node, ctx: EvalCtx): Value { diff --git a/src/engine/types.ts b/src/engine/types.ts index d18b7c5..f009eba 100644 --- a/src/engine/types.ts +++ b/src/engine/types.ts @@ -4,6 +4,9 @@ Decimal.set({ precision: 40, toExpNeg: -9, toExpPos: 21 }); export { Decimal }; +/** Shared here (not in evaluator.ts) so unitdata.ts can use it too without a cycle. */ +export const PI = new Decimal("3.14159265358979323846264338327950288419716939937510"); + export type Dimension = | "scalar" | "length" diff --git a/src/engine/unitdata.ts b/src/engine/unitdata.ts index 7b6692e..67548df 100644 --- a/src/engine/unitdata.ts +++ b/src/engine/unitdata.ts @@ -1,7 +1,7 @@ // Conversion ratios. Base units per dimension: length=meter, area=m², // volume=m³, weight=gram, time=second, angle=radian, data=bit, // temperature=kelvin (ratio+offset). -import { Decimal, Dimension } from "./types"; +import { Decimal, Dimension, PI } from "./types"; export interface UnitData { id: string; @@ -79,7 +79,7 @@ export const UNIT_DATA: UnitData[] = [ // Angle (base: radian) { id: "radian", category: "Angle", dimension: "angle", ratio: "1" }, - { id: "degree", category: "Angle", dimension: "angle", ratio: String(Math.PI / 180) }, + { id: "degree", category: "Angle", dimension: "angle", ratio: PI.div(180).toString() }, // Data (base: bit) { id: "bit", category: "Data", dimension: "data", ratio: "1", prefixes: "data" },