From 4efc8d2c03e91ea330cbb9366a60e7405ebca8de Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 11 Apr 2026 20:58:46 +0300 Subject: Refactor number.go Float64() to return errors - Float64() now returns (float64, error) instead of just float64 - All arithmetic methods (Add, Sub, Mul, Div, Pow, Mod, Compare) return errors - IsString() and IsSymbol() added to Number interface - Float and Rat now implement IsString() and IsSymbol() - StringNum and Symbol updated to implement complete Number interface - IsZero() updated to use val, _ := Float64() pattern - ToFloat() updated to ignore error from Float64()} --- internal/rpn/rpn_parse.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'internal/rpn/rpn_parse.go') diff --git a/internal/rpn/rpn_parse.go b/internal/rpn/rpn_parse.go index bf9a613..19e35fa 100644 --- a/internal/rpn/rpn_parse.go +++ b/internal/rpn/rpn_parse.go @@ -345,13 +345,17 @@ func (r *RPN) evaluate(input string, tokens []string) (string, error) { if err != nil { return "", fmt.Errorf("insufficient operands for %s: stack is empty", nextToken) } - if err := r.vars.SetVariable(token, val.Float64()); err != nil { + valF, err := val.Float64() + if err != nil { + return "", fmt.Errorf("failed to get float64 value for variable %q: %w", token, err) + } + if err := r.vars.SetVariable(token, valF); err != nil { return "", fmt.Errorf("failed to set variable %q: %w", token, err) } // Skip the operator token (next one) since we handled it inline // We've consumed both tokens, so we're done // Return confirmation message showing the assignment - return fmt.Sprintf("%s = %.10g", token, val.Float64()), nil + return fmt.Sprintf("%s = %.10g", token, valF), nil } else if _, err := strconv.ParseFloat(token, 64); err != nil && isValidIdentifier(token) { // This token is a variable name (not a number) shouldPushName = true -- cgit v1.2.3