Add math stdlib with formulas/plots and polish the docs view.

Ship Num/Formula runtime, bilingual math libs, SVG plots with axes/grid, and view UX for collapsible folders plus centered plots.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-08-05 11:30:47 +08:00
1 parent a53ebb65ee
commit dcd0cdb8f7
40 files changed
+3553 -276

No files matched your search

+14 -1
View File
@@ -2,16 +2,22 @@
use std::fmt;
use crate::formula::Expr as FormulaExpr;
#[derive(Debug, Clone, PartialEq)]
pub enum Value {
None,
Bool(bool),
Int(i64),
/// Floating-point number (`type` → `num`).
Num(f64),
Text(String),
/// Single-column table rows (v0); multi-column later.
List(Vec<Value>),
/// JSON object / string-keyed map (insertion order).
Map(Vec<(String, Value)>),
/// Parsed symbolic expression (`type` → `formula`).
Formula(FormulaExpr),
}
impl Value {
@@ -20,9 +26,11 @@ impl Value {
Value::None => false,
Value::Bool(b) => *b,
Value::Int(n) => *n != 0,
Value::Num(n) => *n != 0.0 && !n.is_nan(),
Value::Text(s) => !s.is_empty(),
Value::List(xs) => !xs.is_empty(),
Value::Map(xs) => !xs.is_empty(),
Value::Formula(_) => true,
}
}
@@ -32,9 +40,14 @@ impl Value {
Value::Bool(true) => "True".into(),
Value::Bool(false) => "False".into(),
Value::Int(n) => n.to_string(),
Value::Num(n) => crate::formula::format_num(*n),
Value::Text(s) => s.clone(),
Value::List(_) => "<list>".into(),
Value::List(xs) => {
let parts: Vec<String> = xs.iter().map(|v| v.as_display()).collect();
format!("[{}]", parts.join(", "))
}
Value::Map(_) => "<map>".into(),
Value::Formula(e) => e.as_display(),
}
}
}