From 515ce3752b5470ade8cd9f956f9d8f9cc80ac06f Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 25 Mar 2026 16:47:47 +0200 Subject: docs: Update README.md and godoc for Boolean-to-Number coercion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added documentation section to README.md explaining automatic coercion - Included usage examples: '5 3 == 1 +', '0 false +', 'true 2 *', '9 3 > 4 5 < +' - Updated Value type godoc to explain coercion behavior (true→1, false→0) - toNumber() function already had good documentation The coercion allows boolean results to be used directly in arithmetic operations, enabling expressions like '5 3 == 1 +' where '5 3 ==' produces false=0, then '0 + 1' produces 1. --- internal/rpn/variables.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'internal') diff --git a/internal/rpn/variables.go b/internal/rpn/variables.go index de98e2f..5214403 100644 --- a/internal/rpn/variables.go +++ b/internal/rpn/variables.go @@ -14,6 +14,14 @@ var ( ) // Value represents a variant type that can hold either a number (float64) or a boolean. +// +// When used in arithmetic operations, boolean values are automatically coerced: +// - true → 1 +// - false → 0 +// +// This allows boolean results from comparison operations to be used directly in +// arithmetic expressions (e.g., "5 3 == 1 +" where "5 3 ==" produces false=0, +// and "0 + 1" produces 1). type Value struct { isBool bool boolVal bool -- cgit v1.2.3