cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

main
012 / internal / functions / values.go
values.go 1.6K
1// Package functions is 012's function library: the FuncDef table, the2// evaluation of formulas (operators and calls), the argument, range and3// criteria helpers functions share, decimal arithmetic, and the4// questions JEV functions ask.5//6// It knows nothing of sheets or storage. A formula reads cells through a7// Reader over a Book, which the engine (internal/sheet) implements, and8// the engine finds functions through the table (LookupFunc) when it9// parses formulas. Dependencies point one way: formula and value below,10// the engine above.11package functions1213import (14 "src.rest/cat/012/internal/formula"15 "src.rest/cat/012/internal/value"16)1718// The library works in the formula and value packages' terms; these19// names keep its tables short, as the engine's do.20type (21 // Value is the computed contents of a cell.22 Value = value.Value23 // Format is a cell's number format.24 Format = value.Format25 // Node is a parsed formula expression.26 Node = formula.Node27 // Addr identifies a cell by zero-based column and row.28 Addr = formula.Addr29 // Rect is an inclusive rectangular range of cells.30 Rect = formula.Rect31)3233func num(v float64) Value { return value.Num(v) }34func boolean(b bool) Value { return value.Boolean(b) }35func str(s string) Value { return value.Str(s) }36func errOf(v Value) *Value { return value.ErrOf(v) }37func toNum(v Value) (float64, *Value) { return value.ToNum(v) }38func text(v Value) string { return value.AsText(v) }39func compare(l, r Value) int { return value.Compare(l, r) }4041func clampInt(v, lo, hi int) int { return max(lo, min(v, hi)) }