buguoshixc/mooncalc/src/engine does not have a README file

    Cell

    pub(all) enum Cell {
    Literal(
    Value
    )
    Formula(String)
    } derive(Eq, Show,
    Debug
    )
    单元格内容:字面值或公式源码。

    CritToken

    type CritToken

    Criteria

    type Criteria

    Ctx

    type Ctx

    Dec

    type Dec

    EvalOptions

    pub(all) struct EvalOptions {
    now : Double?
    } derive(Show,
    Debug
    )
    求值选项。

    EvalOutput

    pub(all) struct EvalOutput {
    value :
    Value

    circular : Bool
    } derive(Show,
    Debug
    )
    单格/单公式求值结果。

    FmtCond

    type FmtCond

    FmtSection

    type FmtSection

    FmtTok

    type FmtTok

    FnSpec

    type FnSpec

    Grid

    pub(all) struct Grid {
    cells : Map[String, Cell]
    } derive(Show,
    Debug
    )
    单元格网格:引擎的唯一输入数据契约。键为 A1 形式的大写地址(CellAddr::key)。

    RecalcOutput

    pub(all) struct RecalcOutput {
    cells : Map[String, EvalOutput]
    parse_errors : Array[(String, String)]
    }
    全网格重算结果。

    SectionChoice

    type SectionChoice

    compare_values

    Excel 比较排序(= < 等):不跨类型强制转换,类型序 number < text < boolean, 文本大小写不敏感,故 "1" = 1 为 FALSE。返回 -1/0/1;错误值传播。

    date_serial

    fn date_serial(y0 : Int, m0 : Int, d0 : Int) -> Result[Int,
    XlError
    ]
    Excel DATE():年参数 0..1899 先 +1900,再按月溢出归一化(故 DATE(1900,0,1) 落在 1899 → #NUM!)。序列日按 Excel/Lotus 日历计算(幻影日 1900-02-29 = 60, DATE(1900,3,0) = 60、DATE(1900,2,30) = 61)。越界(序列 <0 或 >2958465)返回 #NUM!。

    days_in_month

    fn days_in_month(y : Int, m : Int) -> Int
    proleptic Gregorian 月份天数。注意 1900 在此不是闰年:真实 Excel 的 EOMONTH(60,0) 返回 59,即 1900 年 2 月按 28 天计算(显示层仍保留幻影序列 60)。 非法月份返回 0。

    eval_at

    求值网格中某个单元格;空白格返回 Blank。循环引用语义与 recalc 一致。

    eval_formula

    fn eval_formula(formula : String, grid : Grid, options : EvalOptions) -> Result[EvalOutput,
    ParseError
    ]
    解析并求值单条公式(不写入网格)。引用会递归求值。

    解析失败返回 Err(ParseError);求值阶段的错误值(如 #DIV/0!)作为 Ok 中的 Value::Err 返回。超过 Excel 公式限制(8192 字符 / 64 层嵌套)按解析失败处理。

    new_grid

    fn new_grid() -> Grid
    创建一个空的单元格网格。

    number_to_text

    fn number_to_text(d : Double) -> String
    Excel 隐式数字→文本(&/CONCAT 用的 General 格式):先舍入到 15 位有效数字, 十进制指数在 [-18, 19] 内用定点表示,否则科学计数;科学计数尾数去尾零,定点整数补零。

    recalc

    fn recalc(grid : Grid, options : EvalOptions) -> RecalcOutput
    按依赖关系重算整个网格(DFS + 记忆化 + 环检测)。

    循环引用复刻 Excel 默认(迭代计算关闭):环上单元格结果为 0,元数据 circular: true。

    round_excel

    fn round_excel(d : Double, digits : Int, mode : Int) -> Double
    Excel 十进制舍入(先归一到 15 位有效数字再舍入,避免二进制浮点尾差)。 digits 为保留小数位(负数舍入到十/百…位);mode:0=ROUND(四舍五入)、 1=ROUNDUP(远离零)、2=ROUNDDOWN(趋向零)。

    scalarize

    标量化:1×1 区域取其唯一单元格,其余值原样返回。

    serial_to_ymd

    fn serial_to_ymd(serial : Double) -> Result[(Int, Int, Int),
    XlError
    ]
    Excel 序列日 → (年, 月, 日)。含 Lotus 幻影日:序列 60 = 1900-02-29,序列 0 = (1900,1,0)。 非有限值或越界(<0 或 >2958465)返回 #NUM!;小数部分被截断。

    text_format

    fn text_format(d : Double, fmt : String) -> Result[String,
    XlError
    ]
    Excel TEXT():按格式码把数字格式化为文本。支持数字段(0/#/?/千分位/百分号/ 科学计数)、日期时间段(含 [h]/[m]/[s] 累计时长)、条件分段(如 [>100])与 正;负;零;文本四节。子集外格式返回 #VALUE!(含 "General" 关键字,zh-CN Excel 拒绝)。完整子集见 docs/semantics.md「TEXT 子集」。

    to_bool

    Excel 布尔强制转换(逻辑参数):布尔原样;数字≠0→TRUE;空白→FALSE; 文本仅接受大小写不敏感的 "TRUE"/"FALSE",其余→#VALUE!;错误传播。

    to_number

    Excel 数值强制转换(算术运算、数值参数):数字原样;空白→0;布尔→1/0; 文本按 Excel 数字文法解析(含千分位/百分号/科学计数,locale 不变);错误传播; 多格区域→#VALUE!。

    to_text

    Excel 文本强制转换(&、文本参数):数字按 General 格式(15 位有效数字); 布尔→"TRUE"/"FALSE";空白→"";错误传播;多格区域→#VALUE!。